def change_row(filename): path_to_db = os.path.join(DB_FOLDER, filename) table_name = request.form.get('table_name') table_view = mytable.TablesView(path_to_db) conn = sqlite3.connect(path_to_db) cursor = conn.cursor() cursor.execute('PRAGMA table_info(' + table_name + ')') table_info = cursor.fetchall() command = "UPDATE " + table_name + ' SET ' i = 0 while request.form.get('name' + str(i)) != None: name = request.form.get('name' + str(i)) new_value = request.form.get('cell_new' + str(i)) if new_value == '': i += 1 continue if len(table_info[i][2]) == 7: if table_info[i][2][:7] == 'INTEGER': command += '"' + name + '" = ' + new_value + ', ' else: command += '"' + name + '" = \'' + new_value + '\', ' i += 1 command = command[:-2] + ' WHERE (' for i in range(len(table_view.headline_names[table_name])): value = request.form.get('cell_old' + str(i)) if len(table_info[i][2]) == 7: if table_info[i][2][:7] == 'INTEGER': command += '"' + table_view.headline_names[table_name][ i] + '" = ' + value + ' AND ' else: command += '"' + table_view.headline_names[table_name][ i] + '" = \'' + value + '\' AND ' command = command[:-4] + ');' try: cursor.execute(command) conn.commit() except: pass cursor.close() conn.close() command = 'SELECT * FROM ' + table_name rows = get_rows_by_command(filename, command) return render_template('Table.html', filename=filename, table_view=table_view, tablename=table_name, rows=rows)
def add_row(filename): path_to_db = os.path.join(DB_FOLDER, filename) table_name = request.form.get('table_name') command = "" headline = "" i = 0 while request.form.get('name' + str(i)) != None: name = request.form.get('name' + str(i)) newVal = request.form.get(name) if newVal != '': headline += '\'' + name + '\', ' command += '\'' + request.form.get(name) + '\', ' i += 1 command = 'INSERT INTO ' + table_name + ' ( ' + headline[: -2] + ' ) VALUES (' + command[: -2] + ')' conn = sqlite3.connect(path_to_db) cursor = conn.cursor() try: cursor.execute(command) conn.commit() except: pass cursor.close() conn.close() table_view = mytable.TablesView(path_to_db) rows = get_rows_from_bd(filename, table_name) return render_template('Table.html', filename=filename, table_view=table_view, tablename=table_name, rows=rows)
def show_all_row(filename): path_to_db = os.path.join(DB_FOLDER, filename) table_name = request.form.get('table_name') table_view = mytable.TablesView(path_to_db) rows = get_rows_from_bd(filename, table_name) return render_template('Table.html', filename=filename, table_view=table_view, tablename=table_name, rows=rows)
def show_db(filename): path_to_db = os.path.join(DB_FOLDER, filename) table_view = mytable.TablesView(path_to_db) if request.method == 'POST': table_name = request.form.get('name') rows = get_rows_from_bd(filename, table_name) return render_template('Table.html', filename=filename, table_view=table_view, tablename=table_name, rows=rows) return render_template('viewdb.html', filename=filename, table_view=table_view)
def find_row(filename): path_to_db = os.path.join(DB_FOLDER, filename) table_name = request.form.get('table_name') headline = [] patterns = [] search_val = [] i = 0 while request.form.get('name' + str(i)) != None: name = request.form.get('name' + str(i)) headline.append(name) patterns.append(request.form.get(name)) search_val.append(request.form.get(name)) i += 1 table_view = mytable.TablesView(path_to_db) rows = find_rows_from_bd(filename, table_name, headline, patterns) return render_template('Table.html', filename=filename, table_view=table_view, tablename=table_name, rows=rows, search_val=search_val)