protocol = "mysql"
driver = "mysqlconnector"
server = "hadoop.mathsci.denison.edu"
port = 3306
user = "studen_j1"
password = "studen_j1"
database = "book"
template = "{}+{}://{}:{}@{}:{}/{}"
cstring1 = template.format(protocol, driver, user, password, server, port, database)
print(cstring1)
cstring1 = f"{protocol}+{driver}://{user}:{password}@{server}:{port}/{database}"
print(cstring1)
database = "school"
print(cstring1)
import os.path
protocol = "sqlite"
driver = "pysqlite"
dbdir = "../../dbfiles"
database = "book"
cstring2 = f"{protocol}+{driver}:///{os.path.join(dbdir, database + '.db')}"
print(cstring2)
import sqlalchemy as sa
engine = sa.create_engine(cstring)
connection = engine.connect()
try:
connection.close()
except:
pass
del engine
with
/Implicit Cose¶engine = sa.create_engine(cstring)
with engine.connect() as connection:
# Perform database requests and process replies
pass
del engine
engine = sa.create_engine(cstring)
connection = engine.connect()
query = """
SELECT * FROM indicators0
"""
result_proxy = connection.execute(query)
type(result_proxy)
result_list = result_proxy.fetchall()
print(result_list)
for record in result_list:
print(record)
firstrecord = result_list[2]
firstrecord
firstrecord[0]
firstrecord['code']
list(firstrecord.keys())
result_proxy.keys()