def delete_database(shortname="", host=""): DatabaseContainer.delete([shortname]) BindContainer.delete([shortname]) if len(DatabaseContainer.get_databases(host=host)) <= 0: DatabaseContainer.UNIQUE_HOSTS.remove(host) return True update() return False
def delete_server(host=""): databases = DatabaseContainer.get_databases(host=host) shortnames = [list(database.keys())[0] for database in databases] DatabaseContainer.delete(shortnames) BindContainer.delete(shortnames) DatabaseContainer.UNIQUE_HOSTS.remove(host) update() return True
def database_connect(host, shortname): try: BindContainer.add(shortname) except OperationalError: pass if request.args.get("next") != None: print(request.args.get("next")) return redirect(request.args.get("next")) return redirect(url_for('blueprint.database_view_structure', host=host, shortname=shortname))
def decorated_function(host, shortname, table_name=None, section=None): if BindContainer.get(shortname): if not check_connection(DatabaseContainer.get(shortname)): BindContainer.delete(shortname) else: if table_name == None: return f(host, shortname) return f(host, shortname, table_name) url = url_for("blueprint.database_connect", host=host, shortname=shortname) return make_response( render_template("database/error.html", host=host, url=url), 200)
def server_view_users(host): sorted_by_drivers = {} users = {} headers = {} _BINDS = BindContainer.get_all() for _driver in SUPPORTED_DRIVERS: sorted_by_drivers[_driver] = (DatabaseContainer.get_databases( host=host, drivername=_driver)) for drivername, databases in sorted_by_drivers.items(): for database in databases: for shortname, db_properties in database.items(): if shortname in _BINDS: connection = _BINDS[shortname][0] #connection stmt = StatementsChooser.for_[ drivername].get_server_users() result = connection.execute(stmt) headers[drivername] = result.keys() users[drivername] = result.fetchall() break else: continue break return make_response( render_template('server/users.html', host=host, headers=headers, users=users), 200)
def get_table_names(shortname): _temp = BindContainer.get(shortname) if _temp: # _temp[1] = meta return _temp[1].sorted_tables else: return []
def decorated_function(*args, **kwargs): if not DatabaseContainer.get(kwargs["shortname"]): abort(404) if BindContainer.get(kwargs["shortname"]): if not check_connection(DatabaseContainer.get( kwargs["shortname"])): BindContainer.delete(kwargs["shortname"]) else: return f(*args, **kwargs) url = url_for("blueprint.database_connect", host=kwargs["host"], shortname=kwargs["shortname"]) return make_response( render_template("database/error.html", host=kwargs["host"], url=url), 200)
def database_view_operations(host, shortname): error = False c = request.args.get("c") act_db_properties = DatabaseContainer.get(shortname) form = DatabaseEditForm(request.form) if c is not None: if COMMANDS[c](host=host, shortname=shortname): return redirect( url_for("blueprint.server_view_databases", host=host)) else: return redirect('/') if request.method == 'POST': if form.validate(): if check_connection(form.data): DatabaseContainer.add(form.data) DatabaseContainer.delete([shortname]) BindContainer.delete([shortname]) BindContainer.add(form.shortname.data) update() return redirect( url_for("blueprint.database_view_operations", host=host, shortname=form.shortname.data)) else: error = "Unable connect to database." else: if len(form.shortname.errors) > 0: error = "Shortname already exists. Please specify another one." if len(form.database.errors) > 0: error = "Specifed database already exists." else: error = "Please provide correct data." return make_response( render_template('database/operations.html', host=host, form=form, error=error, act_db_properties=act_db_properties), 200)
def table_view_browse(host, shortname, table_name, offset=None, page=None): offset = request.args.get("offset") page = request.args.get("page") if offset is None: offset = DEFAULT_OFFSET else: try: offset = int(offset) except ValueError: offset = DEFAULT_OFFSET if page is None: page = 1 else: try: page = int(page) except ValueError: page = 1 if page <= 0: page = 1 if page - 1 <= 0: prev_ = False else: prev_ = page - 1 offset_ = (offset * page) - offset connection, meta, _ = BindContainer.get(shortname) table = meta.tables[table_name] result = connection.execute(table.select().limit(offset).offset(offset_)) rows = result.fetchall() types = [col.type for col in result.context.compiled.statement.columns] if len(rows) < offset: next_ = False else: next_ = page + 1 return make_response( render_template('table/browse.html', table_name=table_name, keys=result.keys(), rows=rows, types=types, current_page=page, offset=offset, prev=prev_, next=next_, host=host), 200)
def database_view_sql(host, shortname): connection, meta, _ = BindContainer.get(shortname) form = SqlForm(request.form) result = False error = False if request.method == 'POST': if form.validate(): stmt = form.data["stmt"] try: result_ = connection.execute(stmt) result = {} result["labels"] = result_.keys() result["query_result"] = result_.fetchall() except Exception as e: error = e else: error = "Can't validate form." return make_response( render_template('database/sql.html', host=host, result=result, form=form, error=error), 200)
def binds(): binds = BindContainer.get_all() return dict(binds=binds)
def table_view_export(host, shortname, table_name): connection, meta, _ = BindContainer.get(shortname) return make_response(render_template('table/export.html', host=host), 200)
def database_disconnect(host, shortname): BindContainer.delete([shortname]) return redirect(url_for('blueprint.server_view_info', host=host))
def database_view_import(host, shortname): connection, meta, _ = BindContainer.get(shortname) return make_response(render_template('database/import.html', host=host), 200)