diff --git a/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc new file mode 100644 index 0000000..6d438dd Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/__pycache__/config.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app.db b/Labs/lab-SQL/Lab-SQLite/app.db index a61b799..41f65b1 100644 Binary files a/Labs/lab-SQL/Lab-SQLite/app.db and b/Labs/lab-SQL/Lab-SQLite/app.db differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..67f0215 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/__init__.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc new file mode 100644 index 0000000..d033268 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/forms.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000..7ac8a86 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/models.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..e21d9d5 Binary files /dev/null and b/Labs/lab-SQL/Lab-SQLite/app/__pycache__/views.cpython-35.pyc differ diff --git a/Labs/lab-SQL/Lab-SQLite/app/forms.py b/Labs/lab-SQL/Lab-SQLite/app/forms.py index a0d42b1..377c5f2 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/forms.py +++ b/Labs/lab-SQL/Lab-SQLite/app/forms.py @@ -5,5 +5,4 @@ class CustomerForm(Form): company = StringField('company', validators=[DataRequired()]) - email = EmailField('email', validators=[DataRequired()]) - + email = EmailField('email', validators=[DataRequired()]) \ No newline at end of file diff --git a/Labs/lab-SQL/Lab-SQLite/app/models.py b/Labs/lab-SQL/Lab-SQLite/app/models.py index 9be98c2..9534bb3 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/models.py +++ b/Labs/lab-SQL/Lab-SQLite/app/models.py @@ -1,7 +1,16 @@ import sqlite3 as sql -def insert_customer(): +def insert_customer(company,email): # SQL statement to insert into database goes here + with sql.connect('app.db') as con: + cur = con.cursor() + cur.execute('INSERT INTO customers (company,email) VALUES (?,?)',(company,email)) + con.commit() def retrieve_customers(): # SQL statement to query database goes here + with sql.connect('app.db') as con: + con.row_factory = sql.Row + cur = con.cursor() + result = cur.execute('SELECT * FROM customers').fetchall() + return result \ No newline at end of file diff --git a/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html b/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html index 6e74a14..59457cf 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html +++ b/Labs/lab-SQL/Lab-SQLite/app/templates/customer.html @@ -11,6 +11,14 @@

Add Customer to Our Database

+

+ Company name:
+ {{form.company(size=120)}}
+

+

+ Customer email:
+ {{form.email(size=120)}}
+

@@ -20,4 +28,4 @@

Add Customer to Our Database

-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Labs/lab-SQL/Lab-SQLite/app/templates/home.html b/Labs/lab-SQL/Lab-SQLite/app/templates/home.html index e2216db..25781f9 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/templates/home.html +++ b/Labs/lab-SQL/Lab-SQLite/app/templates/home.html @@ -17,8 +17,14 @@

These are all of our awesome customers:

+ {% for customer in customers %} + + {{customer['company']}} + {{customer['email']}} + + {% endfor %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/Labs/lab-SQL/Lab-SQLite/app/views.py b/Labs/lab-SQL/Lab-SQLite/app/views.py index 4fc2de6..f33adaf 100755 --- a/Labs/lab-SQL/Lab-SQLite/app/views.py +++ b/Labs/lab-SQL/Lab-SQLite/app/views.py @@ -1,6 +1,7 @@ from flask import render_template, redirect, request from app import app, models, db from .forms import CustomerForm +#from models import * # Access the models file to use SQL functions @@ -14,11 +15,15 @@ def create_customer(): if form.validate_on_submit(): # Get data from the form # Send data from form to Database + company = form.company.data + email = form.email.data + models.insert_customer(company,email) return redirect('/customers') return render_template('customer.html', form=form) @app.route('/customers') def display_customer(): #Retreive data from database to display + customers = models.retrieve_customers() return render_template('home.html', customers=customers) diff --git a/Labs/lab-SQL/Lab-SQLite/schema.sql b/Labs/lab-SQL/Lab-SQLite/schema.sql index f06fbdb..14d886c 100644 --- a/Labs/lab-SQL/Lab-SQLite/schema.sql +++ b/Labs/lab-SQL/Lab-SQLite/schema.sql @@ -1,2 +1,9 @@ -- Insert code to create Database Schema -- This will create your .db database file for use + +drop table if exists customers; +create table customers ( + customer_id integer primary key, + company text not null, + email text non null +); \ No newline at end of file diff --git a/Labs/lab-SQL/Pokemon.db b/Labs/lab-SQL/Pokemon.db index 7fbc93f..9002478 100644 Binary files a/Labs/lab-SQL/Pokemon.db and b/Labs/lab-SQL/Pokemon.db differ