import mysql.connector
from random import randint

class wezz:
    def __init__(self , a , b, c):
        self.a, self.b, self.c = int(a) , int(b) , int(c)

    def somme(self):
        return self.a**2 + self.b**2 + self.c**2

    def div(self):
        L = [ ]
        for n in range(1 , self.somme()+1):
            if self.somme() % n == 0:
                L.append(n)
        return L

    def fct(self , *args):
        if len( args ) == 0:
            a = self.a
            b = self.b
            c = self.c
        else:
            a = args[0]
            b = args[1]
            c = args[2]
            
        if min(a,b,c) == 0:
            return 0
        else:
            return a * b * c + self.fct(a-1,b-1,c-1)

def insert_sql():
    conn = mysql.connector.connect(
        host="localhost",
        user="root",
        password="")

    cursor = conn.cursor()
    cursor.execute("CREATE DATABASE IF NOT EXISTS wezz")
    cursor.execute("CREATE TABLE IF NOT EXISTS wezz.simulations (id INT PRIMARY KEY AUTO_INCREMENT UNIQUE, a INT, b INT, c INT, s INT)")

    for k in range(100):
        a = randint(1,20)
        b = randint(1,20)
        c = randint(1,20)
        w = wezz(a,b,c)
        s = w.fct()
        requete = "INSERT INTO wezz.simulations (a,b,c,s) VALUES (%s,%s,%s,%s)"
        val = (a,b,c,s)
        cursor.execute(requete , val )

insert_sql()

