[egenix-users] mxODBC doesn't support LIMIT in SELECT?

M.-A. Lemburg mal at egenix.com
Tue Sep 2 22:03:15 CEST 2008


On 2008-09-02 20:43, Minh-Long Pham wrote:
> Hi,
> 
> I've connected to my database through mx.ODBC.Windows functions
> connect() and DriverConnect().
> I was able to execute sql.execute("""SELECT count(*) FROM
> IM1_InventoryMasterfile""") but not
> sql.execute("""SELECT * FROM IM1_InventoryMasterfile LIMIT 5""").
> 
> This is the error that I get:
> mx.ODBC.Error.InterfaceError: ('3700', 1017, '[Best Canada][PUX ODBC
> Driver]Unexpected extra token: 5', 7089)
> 
> Windows ODBC version: 3.525.11.32.0
> Windows Python version: 2.5
> 
> Why does a simple LIMIT 5 not work?

Whether LIMIT works or not does not depend on mxODBC. This is a
feature that your database backend must provide.

Which database are you using ? Does it support LIMIT ?

Note that you can easily fetch just the first 5 rows from the query
using

    cursor.fetchmany(5)

This works even without LIMIT support in the database.

Depending on the ODBC driver you are using, there are also other
ways to further limit the number of rows that the ODBC driver
fetches, e.g. using

    cursor.setcursoroption(SQL.ATTR_MAX_ROWS, 5)

If you want to move around in the result set without actually
fetching rows over the network, you can use

    cursor.scroll(value[,mode='relative'])

However, whether this works depends on the capabilities of the
ODBC driver.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 02 2008)
>>> 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 mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX 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



More information about the egenix-users mailing list