Ejemplo n.º 1
0
def db_template(sql):
    try:
        conn = Connector()
        conn.connect()
        cur = conn.cursor()
        cur.execute(sql)
        conn.commit()
    except Exception as e:
        print('load sql')
        print('e\t' + str(e))
    finally:
        conn.close()
Ejemplo n.º 2
0
def db_template_return(sql):
    rows = []
    try:
        conn = Connector()
        conn.connect()
        cur = conn.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        conn.commit()
    except Exception as e:
        print('load sql')
        print('e\t' + str(e))
    finally:
        conn.close()
        return rows
Ejemplo n.º 3
0
 def remove_category(self):
     try:
         session = Connector(db=os.environ['DB']).session
         category = session.query(Category).get(
             self.categories_list.selectedItems()[0].data(Qt.UserRole))
         session.delete(category)
         session.commit()
         self.restart_ui()
     except IndexError:
         QMessageBox.information(
             None, 'Error',
             'Please, select category item before delete them')
     except IntegrityError:
         QMessageBox.information(
             None, 'Error',
             'You can\'t delete category that refers to item')
Ejemplo n.º 4
0
def database(path='default.db'):
    try:
        con = Connector(path).connect()

        cur = con.cursor()
        cur.execute(
            "CREATE TABLE IF NOT EXISTS brands(brand_id INTEGER PRIMARY KEY,name TEXT NOT NULL)"
        )

        cur.execute(
            "CREATE TABLE IF NOT EXISTS t_types(type_id INTEGER PRIMARY KEY NOT NULL,name text NOT NULL)"
        )

        cur.execute(
            "CREATE TABLE IF NOT EXISTS storagespaces(storage_id INTEGER PRIMARY KEY, stillage TEXT NOT NULL,x INTEGER NOT NULL CHECK (x > 0),y INTEGER NOT NULL CHECK (y > 0))"
        )

        cur.execute(
            "CREATE TABLE IF NOT EXISTS wheel(wheel_id INTEGER PRIMARY KEY,width INTEGER NOT NULL CHECK(width > 0),height INTEGER NOT NULL CHECK(height > 0),inches DOUBLE NOT NULL CHECK(inches > 0),t_depth DOUBLE,t_type INTEGER NOT NULL,brand INTEGER NOT NULL,dot INTEGER NOT NULL,storage_space_id INTEGER NOT NULL)"
        )
        con.commit()
    except lite.Error, e:

        print "Error %s:" % e.args[0]