Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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
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
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