How to use the pg8000.DBAPI.connect 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 AppEnlight / appenlight-client-python / appenlight_client / tests.py View on Github external
def test_pg8000(self):
        try:
            import pg8000
        except ImportError:
            return
        conn = pg8000.DBAPI.connect(host="127.0.0.1", user="test",
                                    password="test")
        c = conn.cursor()
        c.execute(self.stmt)
        c.fetchone()
        c.close()
        conn.close()
        stats, result = get_local_storage(local_timing).get_thread_stats()
        assert len(result) == 2
github johnflan / Twitter-4-Traffic / scrapbook / pt / db.py View on Github external
def connect(**db):
    try:
        # get a connection, if a connect cannot be made an exception will be raised here
        conn = DBAPI.connect(**db)
        # conn.cursor will return a cursor object, you can use this cursor to perform queries
        cursor = conn.cursor()
    except:
        # Get the most recent exception
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        # Exit the script and print an error telling what happened.
        sys.exit("Database connection failed! -> %s" % (exceptionValue))
    return cursor,conn
github johnflan / Twitter-4-Traffic / data_acquisition / cluster / slice_cluster.py View on Github external
def connect(**db):
    try:
        # get a connection, if a connect cannot be made an exception will be raised here
        conn = DBAPI.connect(**db)
        # conn.cursor will return a cursor object, you can use this cursor to perform queries
        cursor = conn.cursor()
    except:
        # Get the most recent exception
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        # Exit the script and print an error telling what happened.
        sys.exit("Database connection failed! -> %s" % (exceptionValue))
    return cursor,conn
github johnflan / Twitter-4-Traffic / data_acquisition / label / label1.py View on Github external
def connect(**db):
    try:
        # get a connection, if a connect cannot be made an exception will be raised here
        conn = DBAPI.connect(**db)
        # conn.cursor will return a cursor object, you can use this cursor to perform queries
        cursor = conn.cursor()
    except:
        # Get the most recent exception
        exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
        # Exit the script and print an error telling what happened.
        sys.exit("Database connection failed! -> %s" % (exceptionValue))
    return cursor,conn
github amplab / benchmark / runner / prepare_benchmark.py View on Github external
def prepare_redshift_dataset(opts):
  def query_and_print(cursor, query):
    cursor.execute(query)
    for res in cursor:
      print res
  
  def query_with_catch(cursor, query):
    try: 
      cursor.execute(query)
    except pg8000.errors.InternalError as e:
      print >> stderr, "Received error from pg8000: %s" % e
      print >> stderr, "Attempting to continue..."
  
  conn = DBAPI.connect(
    host = opts.redshift_host,
    database = opts.redshift_database,

    user = opts.redshift_username,
    password = opts.redshift_password,
    port = 5439,
    socket_timeout=60 * 45)
  cursor = conn.cursor()
  cred = "CREDENTIALS 'aws_access_key_id=%s;aws_secret_access_key=%s'" % (
      opts.aws_key_id,
      opts.aws_key)

  try:
    cursor.execute("DROP TABLE rankings;")
  except Exception:
    pass
github amplab / benchmark / runner / run_query.py View on Github external
def run_redshift_benchmark(opts):
  conn = DBAPI.connect(
    host = opts.redshift_host,
    database = opts.redshift_database,
    user = opts.redshift_username,
    password = opts.redshift_password,
    port = 5439,
    socket_timeout=6000)
  print >> stderr, "Connecting to Redshift..."
  cursor = conn.cursor()

  print >> stderr, "Connection succeeded..."
  times = []
  # Clean up old table if still exists
  try:
    cursor.execute(CLEAN_QUERY)
  except:
    pass