How to use the pg8000.paramstyle function in pg8000

To help you get started, we’ve selected a few pg8000 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testPyformat(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "pyformat"
            c1 = self.db.cursor()
            c1.execute(
                "SELECT f1, f2, f3 FROM t1 WHERE f1 > %(f1)s", {"f1": 3})
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.commit()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testFormat(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "format"
            c1 = self.db.cursor()
            c1.execute("SELECT f1, f2, f3 FROM t1 WHERE f1 > %s", (3,))
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.commit()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testNamed(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "named"
            c1 = self.db.cursor()
            c1.execute(
                "SELECT f1, f2, f3 FROM t1 WHERE f1 > :f1", {"f1": 3})
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.rollback()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testQmark(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "qmark"
            c1 = self.db.cursor()
            c1.execute("SELECT f1, f2, f3 FROM t1 WHERE f1 > ?", (3,))
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.rollback()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testNumeric(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "numeric"
            c1 = self.db.cursor()
            c1.execute("SELECT f1, f2, f3 FROM t1 WHERE f1 > :1", (3,))
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.rollback()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github mfenniak / pg8000 / tests / test_dbapi.py View on Github external
def testNumeric(self):
        orig_paramstyle = pg8000.paramstyle
        try:
            pg8000.paramstyle = "numeric"
            c1 = self.db.cursor()
            c1.execute("SELECT f1, f2, f3 FROM t1 WHERE f1 > :1", (3,))
            while 1:
                row = c1.fetchone()
                if row is None:
                    break
                f1, f2, f3 = row
            self.db.rollback()
        finally:
            pg8000.paramstyle = orig_paramstyle
            c1.close()
github gramps-project / addons-source / DBAPIBackend / dbapi_support / postgresql.py View on Github external
import pg8000

pg8000.paramstyle = 'qmark'

class Postgresql(object):
    def __init__(self, *args, **kwargs):
        self.connection = pg8000.connect(*args, **kwargs)

    def execute(self, *args, **kwargs):
        self.cursor = self.connection.cursor()
        self.cursor.execute(*args, **kwargs)

    def fetchone(self):
        return self.cursor.fetchone()

    def fetchall(self):
        return self.cursor.fetchall()

    def commit(self):
github philsch / ansible-redshift / lib / redshift_user.py View on Github external
"login_password": "password",
        "login_ssl": "ssl",
        "port": "port",
        "db": "database"
    }
    kw = dict((params_map[k], v) for (k, v) in iteritems(module.params)
              if k in params_map and v != "")

    # If a login_unix_socket is specified, incorporate it here.
    is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost"
    if is_localhost and module.params["login_unix_socket"] != "":
        kw["host"] = module.params["login_unix_socket"]

    cursor = None
    try:
        pg8000.paramstyle = "pyformat"
        db_connection = pg8000.connect(**kw)
        db_connection.autocommit = False
        cursor = db_connection.cursor()
    except InterfaceError:
        e = get_exception()
        module.fail_json(msg="unable to connect to database, check credentials and SSL flag!: %s " % e)
    except Exception:
        e = get_exception()
        module.fail_json(msg="unable to connect to database: %s" % e)

    kw = {'user': user, 'group': group}
    changed = False
    user_added = False
    group_added = False
    user_removed = False
    group_removed = False
github zenoss / ZenPacks.zenoss.PostgreSQL / src / pg8000 / pg8000 / core.py View on Github external
def execute(self, cursor, operation, vals):
        if vals is None:
            vals = ()
        paramstyle = pg8000.paramstyle
        cache = self._caches[paramstyle]

        try:
            statement, make_args = cache['statement'][operation]
        except KeyError:
            statement, make_args = convert_paramstyle(paramstyle, operation)
            cache['statement'][operation] = statement, make_args

        args = make_args(vals)
        params = self.make_params(args)

        key = tuple(oid for oid, x, y in params), operation

        try:
            ps = cache['ps'][key]
            cursor.ps = ps
github smartsdk / ngsi-timeseries-api / src / translators / timescale.py View on Github external
def setup(self):
        pg8000.paramstyle = "qmark"
        self.conn = pg8000.connect(host=self.host, port=self.port, ssl_context=self.ssl,
                                   database=self.db_name,
                                   user=self.db_user, password=self.db_pass)
        self.conn.autocommit = True
        self.cursor = self.conn.cursor()