Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flask integration] Vertica-python integration with flask is not working for update table #364

Open
singhpratibha58 opened this issue Mar 27, 2020 · 2 comments
Labels

Comments

@singhpratibha58
Copy link

singhpratibha58 commented Mar 27, 2020

User is able to create table, insert , delete records but update query is not working . It is not showing any error message and just refreshing the page.Here is the script:

import os
from flask import Flask
from flask import render_template
from flask import request
from flask import redirect
from flask_sqlalchemy import SQLAlchemy
 
app = Flask(__name__)
app.config.update(
    SECRET_KEY='',
    SQLALCHEMY_DATABASE_URI='vertica+vertica_python://<dbuser>:<dbpassword>@<dbmachineip>:<dbport>/<dbname>',
    SQLALCHEMY_TRACK_MODIFICATIONS= False
    )
 
db = SQLAlchemy(app)
 
class Employee(db.Model):
    emp_name = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)
 
    def __repr__(self):
        return "<Employeename: {}>".format(self.emp_name)
 
 
@app.route("/", methods=["GET", "POST"])
def home():
    employees = None
    if request.form:
        try:
            employee = Employee(emp_name=request.form.get("emp_name"))
            db.session.add(employee)
            db.session.commit()
        except Exception as e:
            print("Failed to show employee name ")
            print(e)
    employees = Employee.query.all()
    return render_template("home.html", employees=employees)
 
 
@app.route("/update", methods=["POST"])
try:
        new_name = request.form.get("newname")
        old_name = request.form.get("oldname")
        employees = Employee.query.filter_by(emp_name=old_name).first()
        employees.emp_name = new_name
        db.session.commit()
    except Exception as e:
        print("Couldn't update employee name")
        print(e)
    return redirect("/")
 
 
@app.route("/delete", methods=["POST"])
def delete():
    emp_name = request.form.get("delname")
    employees = Employee.query.filter_by(emp_name=emp_name).first()
    db.session.delete(employees)
    db.session.commit()
    return redirect("/")
 
 
if __name__ == "__main__":
    db.create_all()
    app.run(host='ServerHostIP')
@sitingren
Copy link
Member

Please provide the version info for those packages you installed. Thanks.

@singhpratibha58
Copy link
Author

I have used 0.10.2 driver version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants