Commit 62e598ae authored by aoh's avatar aoh
Browse files

Use python3 and pymssql in read_sql.py


Signed-off-by: aoh's avataraoh <aoh@lysator.liu.se>
parent 6ad6698f
#!/usr/bin/env python
#!/usr/bin/env python3
import pymysql.cursors
import mysql.connector
from mysql.connector import errorcode
connection = pymysql.connect(host='lysns.lysator.liu.se',
user='lysns',
password='hunter2',
db='lysns',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
cnx = mysql.connector.connect(user='lysns',
password='password',
port='2223',
host='hades',
database='lysns')
with connection.cursor() as cursor:
print("Domain")
cursor.execute('SELECT id, name, uid, dirtybit, deletebit FROM domain')
print(cursor.fetchone())
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cursor = cnx.cursor()
print("Record types")
cursor.execute('SELECT id, name FROM domain')
print(cursor.fetchone())
print("################################################################################")
print("Domain")
print("################################################################################")
query = ("SELECT id,name,uid,dirtybit,deletebit FROM domain")
cursor.execute(query)
print("Subdomain")
cursor.execute('SELECT id, name, ttl, class, rr, destination, domainid, dirtybit, deletebit FROM subdomain')
print(cursor.fetchone())
for (id, name, uid, dirtybit, deletebit) in cursor:
print("{}, {}, {}, {}, {}".format(
id, name, uid, dirtybit, deletebit))
print("Update key")
cursor.execute('SELECT id, subid, update_key, secret FROM update_key')
print(cursor.fetchone())
print("################################################################################")
print("Record types")
print("################################################################################")
query = ("SELECT id,name FROM record_types")
cursor.execute(query)
for (id, name) in cursor:
print("{}, {}".format(
id, name))
print("################################################################################")
print("Subdomain")
print("################################################################################")
query = ("SELECT id, name, ttl, class, rr, destination, domainid, dirtybit, deletebit FROM subdomain")
cursor.execute(query)
for (id, name, ttl, clas, rr, destination, domainid, dirtybit, deletebit) in cursor:
print("{}, {}, {}, {}, {}, {}, {}, {}".format(
id, name, ttl, clas, rr, destination, domainid, dirtybit, deletebit))
print("################################################################################")
print("Update key")
print("################################################################################")
query = ("SELECT id, subid, update_key, secret FROM update_key")
cursor.execute(query)
for (id, subid, update_key, secret) in cursor:
print(id, subid, update_key, secret);
cursor.close()
cnx.close()
finally:
connection.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment