ok
This commit is contained in:
69
MonetDB.py
69
MonetDB.py
@@ -61,32 +61,57 @@ peuplementFlights = r"COPY INTO flights FROM 'C:\\Users\\Public\\2015_Flight_Del
|
|||||||
|
|
||||||
def connect_monetdb():
|
def connect_monetdb():
|
||||||
connection = pymonetdb.connect(username="monetdb", password="monetdb", hostname="localhost", database="demo")
|
connection = pymonetdb.connect(username="monetdb", password="monetdb", hostname="localhost", database="demo")
|
||||||
# create a cursor
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
return connection, cursor
|
return connection, cursor
|
||||||
|
|
||||||
def create_table_monetdb(connection,cursor):
|
def create_table_monetdb():
|
||||||
cursor.execute(createAirline)
|
try:
|
||||||
cursor.execute(createAirports)
|
with connect_monetdb()[0] as conn:
|
||||||
cursor.execute(createFlights)
|
with connect_monetdb()[1] as cursor:
|
||||||
connection.commit()
|
cursor.execute(createAirline)
|
||||||
|
cursor.execute(createAirports)
|
||||||
|
cursor.execute(createFlights)
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
except(pymonetdb.DatabaseError,Exception) as error:
|
||||||
|
print(error)
|
||||||
|
|
||||||
def load_data_monetdb(connection,cursor):
|
def load_data_monetdb():
|
||||||
cursor.execute(peuplementAirlines)
|
try:
|
||||||
cursor.execute(peuplementAirports)
|
with connect_monetdb()[0] as conn:
|
||||||
cursor.execute(peuplementFlights)
|
with connect_monetdb()[1] as cursor:
|
||||||
connection.commit()
|
cursor.execute(peuplementAirports)
|
||||||
|
cursor.execute(peuplementAirlines)
|
||||||
|
cursor.execute(peuplementFlights)
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
except(pymonetdb.DatabaseError,Exception) as error:
|
||||||
|
print(error)
|
||||||
|
|
||||||
def requete_monetdb(connection,cursor,str):
|
def requete_monetdb(str):
|
||||||
cursor.execute(str)
|
try:
|
||||||
connection.commit()
|
with connect_monetdb()[0] as conn:
|
||||||
|
with connect_monetdb()[1] as cursor:
|
||||||
|
cursor.execute(peuplementAirports)
|
||||||
|
cursor.execute(peuplementAirlines)
|
||||||
|
cursor.execute(peuplementFlights)
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
except(pymonetdb.DatabaseError, Exception) as error:
|
||||||
|
print(error)
|
||||||
|
|
||||||
def reset_data_monetdb(connection,cursor):
|
def reset_data_monetdb(connection,cursor):
|
||||||
cursor.execute("DROP TABLE IF EXISTS airlines")
|
try:
|
||||||
cursor.execute("DROP TABLE IF EXISTS airports")
|
with connect_monetdb()[0] as conn:
|
||||||
cursor.execute("DROP TABLE IF EXISTS flights")
|
with connect_monetdb()[1] as cursor:
|
||||||
connection.commit()
|
cursor.execute("DROP TABLE IF EXISTS airlines")
|
||||||
|
cursor.execute("DROP TABLE IF EXISTS airports")
|
||||||
def disconnect_monetdb(connection,cursor):
|
cursor.execute("DROP TABLE IF EXISTS flights")
|
||||||
cursor.close()
|
conn.commit()
|
||||||
connection.close()
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
except(pymonetdb.DatabaseError, Exception) as error:
|
||||||
|
print(error)
|
||||||
11
main.py
11
main.py
@@ -22,10 +22,10 @@ requeteCreateTablePostgreSQL = """CREATE TABLE flights10 AS SELECT * FROM FLIGHT
|
|||||||
requeteDeletePostgreSQL = """DELETE FROM flights WHERE "DAY" > 10"""
|
requeteDeletePostgreSQL = """DELETE FROM flights WHERE "DAY" > 10"""
|
||||||
requeteInsertPostgreSQL = """INSERT INTO flights SELECT * FROM flights10"""
|
requeteInsertPostgreSQL = """INSERT INTO flights SELECT * FROM flights10"""
|
||||||
|
|
||||||
def initMonetDB(conn,cursor):
|
def initMonetDB():
|
||||||
reset_data_monetdb(conn,cursor)
|
reset_data_monetdb()
|
||||||
create_table_monetdb(conn,cursor)
|
create_table_monetdb()
|
||||||
load_data_monetdb(conn,cursor)
|
load_data_monetdb()
|
||||||
|
|
||||||
def execMonetDB(conn,cursor,str):
|
def execMonetDB(conn,cursor,str):
|
||||||
requete_monetdb(conn,cursor, str)
|
requete_monetdb(conn,cursor, str)
|
||||||
@@ -44,7 +44,6 @@ def runMonetDB():
|
|||||||
initMonetDB(conn,cursor)
|
initMonetDB(conn,cursor)
|
||||||
print(time.time() - start)
|
print(time.time() - start)
|
||||||
#execMoneDB(conn,cursor,requeteSelect1MonetDB)
|
#execMoneDB(conn,cursor,requeteSelect1MonetDB)
|
||||||
disconnect_monetdb(conn, cursor)
|
|
||||||
|
|
||||||
def runPostgreSQL():
|
def runPostgreSQL():
|
||||||
reset_database_postgres()
|
reset_database_postgres()
|
||||||
@@ -55,7 +54,5 @@ def runPostgreSQL():
|
|||||||
#requete_postgres(str)
|
#requete_postgres(str)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#PostgreSQL
|
|
||||||
runMonetDB()
|
runMonetDB()
|
||||||
#runPostgreSQL()
|
#runPostgreSQL()
|
||||||
#MonetDB
|
|
||||||
|
|||||||
Reference in New Issue
Block a user