Example #1
0
def init_db():
    """Creates the database tables"""
    with app.app_context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()
Example #2
0
def update_csvMeta(list_Name_Title_Desc):
    with app.app_context():
        db = get_db()
        cur = db.cursor()
        cur.execute('PRAGMA foreign_keys = ON')
        try:
            cur.execute('INSERT INTO csvMeta VALUES (?,?,?)', list_Name_Title_Desc)
            db.commit()
        except:
            e = sys.exc_info()[0]
            print(e)
            pass
Example #3
0
def update_db(csvfile, table='csvFiles'):
    with app.app_context():
        reader = csv.DictReader(open(csvfile, 'rb'))
        container = []
        table_id = re.match(r'.*(\W+)(\w*)(\.csv)$', csvfile).groups()[1]
        row_id = 0 	
        for row in reader:
        	row_id += 1
        	for key in row.keys():
        		container.append((table_id, row_id, json.dumps(key), json.dumps(strip_non_ascii(row[key]))))
        db = get_db()
        db.cursor().executemany('INSERT INTO csvFiles VALUES (?,?,?,?)', container)
        db.commit()
Example #4
0
def update_csvFiles(csvFile, table_name):
    """updates the csvFiles table"""
    with app.app_context():
        reader = csv.DictReader(open(csvFile, 'rb'))
        reader.fieldnames = map(lambda x: re.sub("\W","",x), reader.fieldnames)
        container = []
        row_id = 0
        for row in reader:
        	row_id += 1
        	for key in row.keys():
        		container.append((table_name, row_id, json.dumps(key), json.dumps(strip_non_ascii(row[key]))))
        db = get_db()
        cur = db.cursor()
        cur.execute('PRAGMA foreign_keys = ON')
        try:
            cur.executemany('INSERT INTO csvFiles VALUES (?,?,?,?)', container)
            db.commit()
        except:
            e = sys.exc_info()[0]
            print(e)
            pass
Example #5
0
def query_db(query, args=()):
	with app.app_context():
	    cur = get_db().cursor().execute(query, args)
	    rez = cur.fetchall()
	    return rez