Sync paramstyle between sqlite and mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel

    #1

    Sync paramstyle between sqlite and mysql

    Hello,

    I'm developing an application that accesses both a MySQL and an SQLite
    database. I would like to have named parameters in my SQL and have
    found the following:

    For MySQL my named parameters need to look like this: %(paramname)s
    For SQLite my named parameters need to look like this: :paramname

    I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
    there are five paramstyles, though it wasn't clear if I should expect
    these to be implemented in all DBAPI2 compliant modules. I have found
    that I can set the paramstyle, but it doesn't seem to apply:
    >>import sqlite3 as dbapi2
    >>dbapi2.params tyle
    'qmark'
    >>dbapi2.params tyle = 'format'
    >>dbapi2.params tyle
    'pyformat'

    My sqlite access still requires the 'named' format and not
    'pyformat'.

    Can someone tell me if it's possible to configure a connection or
    cursor to use a particular paramstyle?

    Thanks.
  • Daniel

    #2
    Re: Sync paramstyle between sqlite and mysql

    On Nov 10, 11:00 am, Daniel <daniel.watr... @gmail.comwrote :
    Hello,
    >
    I'm developing an application that accesses both a MySQL and an SQLite
    database.  I would like to have named parameters in my SQL and have
    found the following:
    >
    For MySQL my named parameters need to look like this: %(paramname)s
    For SQLite my named parameters need to look like this: :paramname
    >
    I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
    there are five paramstyles, though it wasn't clear if I should expect
    these to be implemented in all DBAPI2 compliant modules.  I have found
    that I can set the paramstyle, but it doesn't seem to apply:
    >
    >import sqlite3 as dbapi2
    >dbapi2.paramst yle
    'qmark'
    >dbapi2.paramst yle = 'format'
    >dbapi2.paramst yle
    >
    'pyformat'
    >
    My sqlite access still requires the 'named' format and not
    'pyformat'.
    >
    Can someone tell me if it's possible to configure a connection or
    cursor to use a particular paramstyle?
    >
    Thanks.
    If no one has any input, can someone tell me where I should post?

    Thanks

    Comment

    • Jerry Hill

      #3
      Re: Sync paramstyle between sqlite and mysql

      On Mon, Nov 10, 2008 at 1:00 PM, Daniel <daniel.watrous @gmail.comwrote :
      I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
      there are five paramstyles, though it wasn't clear if I should expect
      these to be implemented in all DBAPI2 compliant modules. I have found
      that I can set the paramstyle, but it doesn't seem to apply:
      As far as I understand it, paramstyle is informational, not a setting
      that you can change. You have no choice but to use the paramstyle
      that the provider of the dbapi-compliant module has chosen to use.

      --
      Jerry

      Comment

      • Thorsten Kampe

        #4
        Re: Sync paramstyle between sqlite and mysql

        * Jerry Hill (Tue, 11 Nov 2008 11:24:50 -0500)
        On Mon, Nov 10, 2008 at 1:00 PM, Daniel <daniel.watrous @gmail.comwrote :
        I have read in PEP249 (http://www.python.org/dev/peps/pep-0249/) that
        there are five paramstyles, though it wasn't clear if I should expect
        these to be implemented in all DBAPI2 compliant modules. I have found
        that I can set the paramstyle, but it doesn't seem to apply:
        >
        As far as I understand it, paramstyle is informational, not a setting
        that you can change. You have no choice but to use the paramstyle
        that the provider of the dbapi-compliant module has chosen to use.
        Right.

        Thorsten

        Comment

        Working...