From mathias-gibbens at bethel.edu Tue Aug 10 11:21:35 2010 From: mathias-gibbens at bethel.edu (Mathias Gibbens) Date: Tue Aug 10 17:21:39 2010 Subject: [egenix-users] mxODBC Zope DA .get_connection() Message-ID: <1281453695.24814.32.camel@linux7927> Hello all, In some of my long-running code in Zope, I'm using .get_connection() to get a database connection, and then run some queries. Once I'm done with the queries, I'd like to free up the connection for use in other locations until it is needed again. Is there a way to automatically free connections that are not being used after a period of time? I did find a post from 2005 asking about this, but haven't been able to find anything else helpful. Thanks, Mathias From mal at egenix.com Tue Aug 10 21:37:39 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Tue Aug 10 20:37:42 2010 Subject: [egenix-users] mxODBC Zope DA .get_connection() In-Reply-To: <1281453695.24814.32.camel@linux7927> References: <1281453695.24814.32.camel@linux7927> Message-ID: <4C619C73.2070509@egenix.com> Mathias Gibbens wrote: > Hello all, > > In some of my long-running code in Zope, I'm using .get_connection() to > get a database connection, and then run some queries. Once I'm done with > the queries, I'd like to free up the connection for use in other > locations until it is needed again. Is there a way to automatically free > connections that are not being used after a period of time? > > I did find a post from 2005 > asking about this, but haven't been able to find anything else helpful. You can call the .close() method on the DatabaseConnection object you got from .get_connection(). This will then close the physical database connection and prevent it from being reused in the connection pool. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 10 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From info at egenix.com Thu Aug 19 18:59:05 2010 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu Aug 19 18:06:08 2010 Subject: [egenix-users] ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.0 Message-ID: <4C6D54C9.7030806@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC - Python ODBC Database Interface Version 3.1.0 mxODBC is our commercially supported Python extension providing ODBC database connectivity to Python applications on Windows, Mac OS X, Unix and BSD platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-3.1.0-GA.html ________________________________________________________________________ INTRODUCTION mxODBC provides an easy-to-use, high-performance, reliable and robust Python interface to ODBC compatible databases such as MS SQL Server, MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: http://www.egenix.com/products/python/mxODBC/ The "eGenix mxODBC - Python ODBC Database Interface" product is a commercial extension to our open-source eGenix mx Base Distribution: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The new mxODBC 3.1.0 release comes with many new features and supports more ODBC drivers, manager and platforms than ever before. Release Highlights ------------------ * We've added Python 2.7 support and builds for all platforms. * mxODBC 3.1 adds native support for the Windows 64-bit platforms as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of Python. * mxODBC now fully supports the Oracle Instant Client ODBC driver. * We have updated the support for the latest IBM DB2 9.7 ODBC drivers and enhanced compatibility of mxODBC with the MS SQL Server Native Client ODBC driver on Windows and the Sybase ASE 15 ODBC drivers on Unix. * mxODBC 3.1 adds support for large-scale data warehouse databases Netezza and Teradata. * In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC driver managers, we now also include support for the DataDirect ODBC manager. * The 64-bit support on Unix platforms was updated to support the new unixODBC 2.3.0 version. * We've improved the documentation on how to connect to various popular databases and now include many tips & tricks for each database/driver. * The Python 2.7 memoryview object is now supported as binary data container. * We have simplified handling of database warnings using a new customizable .warningformat attribute. * The catalog methods now accept both Unicode and 8-bit strings as parameters. * You can now select whether to use ANSI (8-bit) or Unicode ODBC APIs in the ODBC drivers, removing unnecessary data conversions and enhancing ODBC driver compatibility. For the full set of changes please check the mxODBC change log: http://www.egenix.com/products/python/mxODBC/changelog.html Feature Highlights ------------------ * Python Database API 2.0 Compliance: the mxODBC API is fully Python DB-API 2.0 compatible and implements a large number of powerful extensions. * Support for all popular ODBC Drivers: mxODBC includes adjustments and work-arounds to support MS SQL Server Native Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual Technologies. * Support for all popular ODBC Driver Managers: mxODBC comes with subpackages for the native Windows and Mac OS X ODBC managers, as well as the ODBC managers unixODBC, iODBC and DataDirect, which are commonly used on Unix systems. * Stable, robust and reliable:the mxODBC API has been in active production use for more than 10 years. * Full Python Support: mxODBC works with Python 2.3, 2.4, 2.5, 2.6 and 2.7. * Full 64-bit Support: mxODBC runs on the following 64-bit platforms: Windows, Linux, FreeBSD and Mac OS X. For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/python/mxODBC/#Features New mxODBC Editions ------------------- Due to popular demand, we have extended the set of available mxODBC editions and included a new low-cost standard edition. mxODBC is now available in thesethree editions: * The low-cost Standard Edition which provides data connectivity to a selected set of database backends. * The Professional Edition, which gives full access to all mxODBC features. * The Product Development Edition, which allows including mxODBC in applications you develop. At the same time we have simplified our license terms to clarify the situation on multi-core and virtual machines. In most cases, you no longer need to purchase more than one license per processor or virtual machine, scaling down the overall license costs significantly compared to earlier mxODBC releases. For a complete overview of the new editions, please see the product page. http://www.egenix.com/products/python/mxODBC/#mxODBCEditions ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/mxODBC/ In order to use the eGenix mxODBC package you will first need to install the eGenix mx Base package: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC release to benefit from the new features and updated ODBC driver support. We have taken special care, not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. Customers who have purchased mxODBC 2.0, 2.1 or 3.0 licenses can upgrade their licenses using the mxODBC Professional Edition Upgrade License. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site http://www.egenix.com/products/python/mxODBC/#Evaluation or by writing to sales@egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 19 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mal at egenix.com Thu Aug 19 23:42:48 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Thu Aug 19 22:44:42 2010 Subject: [egenix-users] ANN: eGenix mxODBC - Python ODBC Database Interface 3.1.0 In-Reply-To: <4C6D54C9.7030806@egenix.com> References: <4C6D54C9.7030806@egenix.com> Message-ID: <4C6D9748.5080104@egenix.com> Dear Users, if you want to use mxODBC on Windows XP, Vista or 7 x64, you will need Win64 versions of our eGenix mx Base distribution. We are currently working on releasing version 3.2.0 of eGenix mx Base. This will come with full 64-bit support for Windows. Until we have a release, you can use these pre-release versions for testing and evaluation: Windows x64 installers: http://downloads.egenix.com/python/egenix-mx-base-3.2.0_dev_20100819.win-amd64-py2.6.msi http://downloads.egenix.com/python/egenix-mx-base-3.2.0_dev_20100819.win-amd64-py2.7.msi Windows x64 prebuilt distutils archives: http://downloads.egenix.com/python/egenix-mx-base-3.2.0_dev_20100819.win-amd64-py2.6.prebuilt.zip http://downloads.egenix.com/python/egenix-mx-base-3.2.0_dev_20100819.win-amd64-py2.7.prebuilt.zip Windows x64 egg archives: http://downloads.egenix.com/python/egenix_mx_base-3.2.0_dev_20100819-py2.6-win-amd64.egg http://downloads.egenix.com/python/egenix_mx_base-3.2.0_dev_20100819-py2.7-win-amd64.egg Source: http://downloads.egenix.com/python/egenix-mx-base-3.2.0_dev_20100819.zip For all other platforms, you can either use the released version egenix-mx-base 3.1: http://www.egenix.com/products/python/mxBase/ or compile the above pre-release on your 64-bit platform using the source archive. Thanks, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 19 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ eGenix Team: M.-A. Lemburg wrote: > ________________________________________________________________________ > > ANNOUNCING > > eGenix.com mxODBC - Python ODBC Database Interface > > Version 3.1.0 > > > mxODBC is our commercially supported Python extension providing > ODBC database connectivity to Python applications > on Windows, Mac OS X, Unix and BSD platforms > > > This announcement is also available on our web-site for online reading: > http://www.egenix.com/company/news/eGenix-mxODBC-3.1.0-GA.html > > ________________________________________________________________________ > > INTRODUCTION > > mxODBC provides an easy-to-use, high-performance, reliable and robust > Python interface to ODBC compatible databases such as MS SQL Server, > MS Access, Oracle Database, IBM DB2 and Informix , Sybase ASE and > Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more: > > http://www.egenix.com/products/python/mxODBC/ > > The "eGenix mxODBC - Python ODBC Database Interface" product is a > commercial extension to our open-source eGenix mx Base Distribution: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > NEWS > > The new mxODBC 3.1.0 release comes with many new features and supports > more ODBC drivers, manager and platforms than ever before. > > > Release Highlights > ------------------ > > * We've added Python 2.7 support and builds for all platforms. > > * mxODBC 3.1 adds native support for the Windows 64-bit platforms > as well as the Mac OS X 10.6 (Snow Leopard) 64-bit builds of > Python. > > * mxODBC now fully supports the Oracle Instant Client ODBC driver. > > * We have updated the support for the latest IBM DB2 9.7 ODBC > drivers and enhanced compatibility of mxODBC with the MS SQL > Server Native Client ODBC driver on Windows and the Sybase ASE 15 > ODBC drivers on Unix. > > * mxODBC 3.1 adds support for large-scale data warehouse databases > Netezza and Teradata. > > * In addition to the Windows, Mac OS X, iODBC and unixODBC ODBC > driver managers, we now also include support for the DataDirect > ODBC manager. > > * The 64-bit support on Unix platforms was updated to support the > new unixODBC 2.3.0 version. > > * We've improved the documentation on how to connect to various > popular databases and now include many tips & tricks for each > database/driver. > > * The Python 2.7 memoryview object is now supported as binary data > container. > > * We have simplified handling of database warnings using a new > customizable .warningformat attribute. > > * The catalog methods now accept both Unicode and 8-bit strings as > parameters. > > * You can now select whether to use ANSI (8-bit) or Unicode ODBC > APIs in the ODBC drivers, removing unnecessary data conversions > and enhancing ODBC driver compatibility. > > For the full set of changes please check the mxODBC change log: > > http://www.egenix.com/products/python/mxODBC/changelog.html > > > Feature Highlights > ------------------ > > * Python Database API 2.0 Compliance: the mxODBC API is fully > Python DB-API 2.0 compatible and implements a large number of > powerful extensions. > > * Support for all popular ODBC Drivers: mxODBC includes > adjustments and work-arounds to support MS SQL Server Native > Client, MS SQL Server ODBC Driver, FreeTDS ODBC Driver, Oracle > Instant Client ODBC Driver, IBM DB2 ODBC Driver, Sybase ASE ODBC > Driver, Netezza ODBC Driver, Teradata ODBC Driver, PostgreSQL > ODBC Driver, MySQL ODBC Driver, .MaxDB ODBC Driver as well as > the ODBC driver sets of EasySoft, DataDirect, OpenLink, Actual > Technologies. > > * Support for all popular ODBC Driver Managers: mxODBC comes with > subpackages for the native Windows and Mac OS X ODBC managers, > as well as the ODBC managers unixODBC, iODBC and DataDirect, > which are commonly used on Unix systems. > > * Stable, robust and reliable:the mxODBC API has been in active > production use for more than 10 years. > > * Full Python Support: mxODBC works with Python 2.3, 2.4, 2.5, 2.6 > and 2.7. > > * Full 64-bit Support: mxODBC runs on the following 64-bit > platforms: Windows, Linux, FreeBSD and Mac OS X. > > For the full set of features mxODBC has to offer, please see: > > http://www.egenix.com/products/python/mxODBC/#Features > > > New mxODBC Editions > ------------------- > > Due to popular demand, we have extended the set of available mxODBC > editions and included a new low-cost standard edition. mxODBC is now > available in thesethree editions: > > * The low-cost Standard Edition which provides data connectivity > to a selected set of database backends. > > * The Professional Edition, which gives full access to all mxODBC > features. > > * The Product Development Edition, which allows including mxODBC > in applications you develop. > > At the same time we have simplified our license terms to clarify the > situation on multi-core and virtual machines. In most cases, you no > longer need to purchase more than one license per processor or virtual > machine, scaling down the overall license costs significantly compared > to earlier mxODBC releases. > > For a complete overview of the new editions, please see the product page. > > http://www.egenix.com/products/python/mxODBC/#mxODBCEditions > > > ________________________________________________________________________ > > DOWNLOADS > > The download archives and instructions for installing the package can > be found at: > > http://www.egenix.com/products/python/mxODBC/ > > In order to use the eGenix mxODBC package you will first need to > install the eGenix mx Base package: > > http://www.egenix.com/products/python/mxBase/ > > ________________________________________________________________________ > > UPGRADING > > Users are encouraged to upgrade to this latest mxODBC release to > benefit from the new features and updated ODBC driver support. > > We have taken special care, not to introduce backwards incompatible > changes, making the upgrade experience as smooth as possible. > > Customers who have purchased mxODBC 2.0, 2.1 or 3.0 licenses can > upgrade their licenses using the mxODBC Professional Edition Upgrade > License. > > If you want to try the new release before purchace, you can request > 30-day evaluation licenses by visiting our web-site > > http://www.egenix.com/products/python/mxODBC/#Evaluation > > or by writing to sales@egenix.com, stating your name (or the name of > the company) and the number of eval licenses that you need. > > _______________________________________________________________________ > > SUPPORT > > Commercial support for this product is available from eGenix.com. > Please see > > http://www.egenix.com/services/support/ > > for details about our support offerings. > > _______________________________________________________________________ > > INFORMATION > > About Python (http://www.python.org/): > > Python is an object-oriented Open Source programming language > which runs on all modern platforms. By integrating ease-of-use, > clarity in coding, enterprise application connectivity and rapid > application design, Python establishes an ideal programming > platform for today's IT challenges. > > About eGenix (http://www.egenix.com/): > > eGenix is a software project, consulting and product company > focusing on expert services and professional quality products for > companies, Python users and developers. > > > Enjoy, From Izzet.Ergas at citrix.com Wed Aug 25 11:26:07 2010 From: Izzet.Ergas at citrix.com (Izzet Ergas) Date: Wed Aug 25 16:26:16 2010 Subject: [egenix-users] Datetime field overflow Message-ID: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> I'm getting this error when querying a MS SQL Server 2005 instance with the SQL Native client using mxODBC 3.0.4. Error: 22008, 0, [Microsoft][SQL Native Client]Datetime field overflow, 7748 I don't always get the error, it only seems to happen for some values passed to the query. I think it is somehow related to the fact that a mx.DateTime object is being passed to the query and somehow being converted to a SQL datetime field in an improper manner. In the query below SessionIdTime is a datetime field in SQL and I'm passing last_record[0] which is a mx.DateTime object. Not sure how to workaround this issue. Any ideas? sql = """ SELECT sd.SessionIdTime, sd.SessionIdSeq FROM SessionDetails sd WHERE sd.SessionIdTime > ? OR (sd.SessionIdTime = ? AND sd.SessionIdSeq > ?) """ db = mx.ODBC.Windows.DriverConnect('DSN=OCS') conn = db.cursor() conn.execute(sql, (last_record[0], last_record[0], last_record[1])) -------------- next part -------------- An HTML attachment was scrubbed... URL: /mailman-archives/egenix-users/attachments/20100825/88016402/attachment.htm From mal at egenix.com Wed Aug 25 18:50:22 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Wed Aug 25 17:50:25 2010 Subject: [egenix-users] Datetime field overflow In-Reply-To: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> References: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> Message-ID: <4C753BBE.7000205@egenix.com> Izzet Ergas wrote: > I'm getting this error when querying a MS SQL Server 2005 instance with the SQL Native client using mxODBC 3.0.4. > > Error: 22008, 0, [Microsoft][SQL Native Client]Datetime field overflow, 7748 > > I don't always get the error, it only seems to happen for some values passed to the query. I think it is somehow related to the fact that a mx.DateTime object is being passed to the query and somehow being converted to a SQL datetime field in an improper manner. > > In the query below SessionIdTime is a datetime field in SQL and I'm passing last_record[0] which is a mx.DateTime object. Not sure how to workaround this issue. > > Any ideas? > > sql = """ > SELECT > sd.SessionIdTime, sd.SessionIdSeq > FROM SessionDetails sd > WHERE sd.SessionIdTime > ? > OR (sd.SessionIdTime = ? AND sd.SessionIdSeq > ?) > """ > db = mx.ODBC.Windows.DriverConnect('DSN=OCS') > conn = db.cursor() > conn.execute(sql, (last_record[0], last_record[0], last_record[1])) This problem is related to the way the SQL Native Server ODBC drivers handles timestamps. mxODBC will send the data to the ODBC driver in the native ODBC format for timestamps: http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/thread/ac1b5a6d-5e64-4603-9c92-b75ba4e51bf2/ If the timestamp contains a seconds fraction that cannot be represented with the database field type, an error is raised (since this causes data to be lost during INSERT). As a result, whether or not you are getting the error depends on the seconds fraction value. The only way around this is to make sure that the fractional value can be represented in SQL Server's datetime type. Here's a helper for doing that: from mx import DateTime def round_seconds(datetime, digits=2): return DateTime.DateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, round(datetime.second, digits)) For egenix-mx-base 3.2, we'll have a .rebuild() method on DateTime objects to make this easier (much like the one we already have on mxURL objects). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 25 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From Izzet.Ergas at citrix.com Wed Aug 25 14:07:39 2010 From: Izzet.Ergas at citrix.com (Izzet Ergas) Date: Wed Aug 25 19:07:56 2010 Subject: [egenix-users] Datetime field overflow In-Reply-To: <4C753BBE.7000205@egenix.com> References: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> <4C753BBE.7000205@egenix.com> Message-ID: <18A0150F50930146A769E0211F1C1BDC1561D4DC5D@FTLPMAILBOX03.citrite.net> Thank you. That explains it. One problem with your workaround though. The second field is represented as a float in the DateTime module so the round() function doesn't help. From what I've gathered this is because many decimal values (like 44.44 for example) cannot be represented exactly as a float. Even using printf to convert to a string and concatenating the value to two decimal places won't work because the result will be changed back to a float in the DateTime object. datetime.second = 44.440000000002328 round(datetime.second,2) = 44.439999999999998 -----Original Message----- From: M.-A. Lemburg [mailto:mal@egenix.com] Sent: Wednesday, August 25, 2010 11:50 AM To: Izzet Ergas Cc: 'egenix-users@egenix.com' Subject: Re: [egenix-users] Datetime field overflow Izzet Ergas wrote: > I'm getting this error when querying a MS SQL Server 2005 instance with the SQL Native client using mxODBC 3.0.4. > > Error: 22008, 0, [Microsoft][SQL Native Client]Datetime field overflow, 7748 > > I don't always get the error, it only seems to happen for some values passed to the query. I think it is somehow related to the fact that a mx.DateTime object is being passed to the query and somehow being converted to a SQL datetime field in an improper manner. > > In the query below SessionIdTime is a datetime field in SQL and I'm passing last_record[0] which is a mx.DateTime object. Not sure how to workaround this issue. > > Any ideas? > > sql = """ > SELECT > sd.SessionIdTime, sd.SessionIdSeq > FROM SessionDetails sd > WHERE sd.SessionIdTime > ? > OR (sd.SessionIdTime = ? AND sd.SessionIdSeq > ?) > """ > db = mx.ODBC.Windows.DriverConnect('DSN=OCS') > conn = db.cursor() > conn.execute(sql, (last_record[0], last_record[0], last_record[1])) This problem is related to the way the SQL Native Server ODBC drivers handles timestamps. mxODBC will send the data to the ODBC driver in the native ODBC format for timestamps: http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/thread/ac1b5a6d-5e64-4603-9c92-b75ba4e51bf2/ If the timestamp contains a seconds fraction that cannot be represented with the database field type, an error is raised (since this causes data to be lost during INSERT). As a result, whether or not you are getting the error depends on the seconds fraction value. The only way around this is to make sure that the fractional value can be represented in SQL Server's datetime type. Here's a helper for doing that: from mx import DateTime def round_seconds(datetime, digits=2): return DateTime.DateTime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, round(datetime.second, digits)) For egenix-mx-base 3.2, we'll have a .rebuild() method on DateTime objects to make this easier (much like the one we already have on mxURL objects). -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 25 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mal at egenix.com Wed Aug 25 21:18:57 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Wed Aug 25 20:19:01 2010 Subject: [egenix-users] Datetime field overflow In-Reply-To: <18A0150F50930146A769E0211F1C1BDC1561D4DC5D@FTLPMAILBOX03.citrite.net> References: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> <4C753BBE.7000205@egenix.com> <18A0150F50930146A769E0211F1C1BDC1561D4DC5D@FTLPMAILBOX03.citrite.net> Message-ID: <4C755E91.7090808@egenix.com> Izzet Ergas wrote: > Thank you. That explains it. > > One problem with your workaround though. The second field is represented as a float in the DateTime module so the round() function doesn't help. From what I've gathered this is because many decimal values (like 44.44 for example) cannot be represented exactly as a float. Even using printf to convert to a string and concatenating the value to two decimal places won't work because the result will be changed back to a float in the DateTime object. > > datetime.second = 44.440000000002328 > round(datetime.second,2) = 44.439999999999998 You have a point there. We should probably round to the nearest nanosecond in mxODBC to get around that problem: >>> int((44.44 - 44) * 1e9 + 0.5) 440000000 An alternative work-around would be using Python datetime.datetime objects, since these store the second fraction as microseconds integer. In any case, we'll look for a solution. Thanks for bringing this up. > -----Original Message----- > From: M.-A. Lemburg [mailto:mal@egenix.com] > Sent: Wednesday, August 25, 2010 11:50 AM > To: Izzet Ergas > Cc: 'egenix-users@egenix.com' > Subject: Re: [egenix-users] Datetime field overflow > > Izzet Ergas wrote: >> I'm getting this error when querying a MS SQL Server 2005 instance with the SQL Native client using mxODBC 3.0.4. >> >> Error: 22008, 0, [Microsoft][SQL Native Client]Datetime field overflow, 7748 >> >> I don't always get the error, it only seems to happen for some values passed to the query. I think it is somehow related to the fact that a mx.DateTime object is being passed to the query and somehow being converted to a SQL datetime field in an improper manner. >> >> In the query below SessionIdTime is a datetime field in SQL and I'm passing last_record[0] which is a mx.DateTime object. Not sure how to workaround this issue. >> >> Any ideas? >> >> sql = """ >> SELECT >> sd.SessionIdTime, sd.SessionIdSeq >> FROM SessionDetails sd >> WHERE sd.SessionIdTime > ? >> OR (sd.SessionIdTime = ? AND sd.SessionIdSeq > ?) >> """ >> db = mx.ODBC.Windows.DriverConnect('DSN=OCS') >> conn = db.cursor() >> conn.execute(sql, (last_record[0], last_record[0], last_record[1])) > > This problem is related to the way the SQL Native Server ODBC drivers > handles timestamps. mxODBC will send the data to the ODBC driver in > the native ODBC format for timestamps: > > http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/thread/ac1b5a6d-5e64-4603-9c92-b75ba4e51bf2/ > > If the timestamp contains a seconds fraction that cannot be > represented with the database field type, an error is raised > (since this causes data to be lost during INSERT). > > As a result, whether or not you are getting the error depends > on the seconds fraction value. The only way around this is > to make sure that the fractional value can be represented > in SQL Server's datetime type. > > Here's a helper for doing that: > > from mx import DateTime > > def round_seconds(datetime, digits=2): > return DateTime.DateTime(datetime.year, > datetime.month, > datetime.day, > datetime.hour, > datetime.minute, > round(datetime.second, digits)) > > For egenix-mx-base 3.2, we'll have a .rebuild() method > on DateTime objects to make this easier (much like the > one we already have on mxURL objects). > -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 25 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From Izzet.Ergas at citrix.com Thu Aug 26 15:24:47 2010 From: Izzet.Ergas at citrix.com (Izzet Ergas) Date: Thu Aug 26 20:24:58 2010 Subject: [egenix-users] Datetime field overflow In-Reply-To: <4C755E91.7090808@egenix.com> References: <18A0150F50930146A769E0211F1C1BDC1561D4DC5A@FTLPMAILBOX03.citrite.net> <4C753BBE.7000205@egenix.com> <18A0150F50930146A769E0211F1C1BDC1561D4DC5D@FTLPMAILBOX03.citrite.net> <4C755E91.7090808@egenix.com> Message-ID: <18A0150F50930146A769E0211F1C1BDC1561D4DC68@FTLPMAILBOX03.citrite.net> Thanks, switching to datetime.datetime objects fixed the problem completely. -----Original Message----- From: M.-A. Lemburg [mailto:mal@egenix.com] Sent: Wednesday, August 25, 2010 2:19 PM To: Izzet Ergas Cc: 'egenix-users@egenix.com' Subject: Re: [egenix-users] Datetime field overflow Izzet Ergas wrote: > Thank you. That explains it. > > One problem with your workaround though. The second field is represented as a float in the DateTime module so the round() function doesn't help. From what I've gathered this is because many decimal values (like 44.44 for example) cannot be represented exactly as a float. Even using printf to convert to a string and concatenating the value to two decimal places won't work because the result will be changed back to a float in the DateTime object. > > datetime.second = 44.440000000002328 > round(datetime.second,2) = 44.439999999999998 You have a point there. We should probably round to the nearest nanosecond in mxODBC to get around that problem: >>> int((44.44 - 44) * 1e9 + 0.5) 440000000 An alternative work-around would be using Python datetime.datetime objects, since these store the second fraction as microseconds integer. In any case, we'll look for a solution. Thanks for bringing this up. > -----Original Message----- > From: M.-A. Lemburg [mailto:mal@egenix.com] > Sent: Wednesday, August 25, 2010 11:50 AM > To: Izzet Ergas > Cc: 'egenix-users@egenix.com' > Subject: Re: [egenix-users] Datetime field overflow > > Izzet Ergas wrote: >> I'm getting this error when querying a MS SQL Server 2005 instance with the SQL Native client using mxODBC 3.0.4. >> >> Error: 22008, 0, [Microsoft][SQL Native Client]Datetime field overflow, 7748 >> >> I don't always get the error, it only seems to happen for some values passed to the query. I think it is somehow related to the fact that a mx.DateTime object is being passed to the query and somehow being converted to a SQL datetime field in an improper manner. >> >> In the query below SessionIdTime is a datetime field in SQL and I'm passing last_record[0] which is a mx.DateTime object. Not sure how to workaround this issue. >> >> Any ideas? >> >> sql = """ >> SELECT >> sd.SessionIdTime, sd.SessionIdSeq >> FROM SessionDetails sd >> WHERE sd.SessionIdTime > ? >> OR (sd.SessionIdTime = ? AND sd.SessionIdSeq > ?) >> """ >> db = mx.ODBC.Windows.DriverConnect('DSN=OCS') >> conn = db.cursor() >> conn.execute(sql, (last_record[0], last_record[0], last_record[1])) > > This problem is related to the way the SQL Native Server ODBC drivers > handles timestamps. mxODBC will send the data to the ODBC driver in > the native ODBC format for timestamps: > > http://social.msdn.microsoft.com/forums/en-US/sqldataaccess/thread/ac1b5a6d-5e64-4603-9c92-b75ba4e51bf2/ > > If the timestamp contains a seconds fraction that cannot be > represented with the database field type, an error is raised > (since this causes data to be lost during INSERT). > > As a result, whether or not you are getting the error depends > on the seconds fraction value. The only way around this is > to make sure that the fractional value can be represented > in SQL Server's datetime type. > > Here's a helper for doing that: > > from mx import DateTime > > def round_seconds(datetime, digits=2): > return DateTime.DateTime(datetime.year, > datetime.month, > datetime.day, > datetime.hour, > datetime.minute, > round(datetime.second, digits)) > > For egenix-mx-base 3.2, we'll have a .rebuild() method > on DateTime objects to make this easier (much like the > one we already have on mxURL objects). > -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 25 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/