Review Databases and Objects

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

09/04/2015Unit 2 (b) Back-Office processes Unit 2 Assessment Criteria (b) 10 marks.
Database Management: Getting Data Together Chapter 14.
CSC 2720 Building Web Applications Database and SQL.
Databases and Database Management Systems
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Database Systems Marcus Kaiser School of Computing Science Newcastle University.
Web Application Development. Define ER model in QSEE Generate SQL Create Database mySQL Write Script to use TableEditor class Process to create A simple.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
© 2003 By Default! A Free sample background from Slide 1 Week 2  Free PHP Hosting Setup  PHP Backend  Backend Security 
Introduction to MySQL Lab no. 10 Advance Database Management System.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
Technology & Management Club Development Software Overview.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Creating PHPs to Insert, Update, and Delete Data CS 320.
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
Handling Semantic Data for Software Projects Data Management CSE G674 – SW Engineering Project.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT395, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT395, Week 12 Storage, Grid Computing, Review This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
INF1343, Week 6 Implementing a Database with SQL This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT395, Week 11 Review, Permissions Physical Storage and Performance This presentation is licensed under Creative Commons Attribution License, v. 3.0.
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Database Design and Implementation
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a.
CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
SELECT, IMPLEMENT & USE TODAY’S ADVANCED BUSINESS SYSTEMS
Database Development Lifecycle
Chengyu Sun California State University, Los Angeles
Database Design and Implementation
Translating ER into Relations; Normalization
Web Routing Designing an Interface
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Database application MySQL Database and PhpMyAdmin
Database Design and Implementation
Data Modeling and Database Design
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 6, 2016
DBM 502 Competitive Success-- snaptutorial.com
DBM 502 Education for Service-- snaptutorial.com
DBM 502 Teaching Effectively-- snaptutorial.com
Login & administration page
Web Systems Development (CSC-215)
Teaching slides Chapter 8.
Web Programming Language
Databases and Information Management
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 5, 2017
Database Management Systems
Grocery Store Outline csc242 – web programming.
Databases and Information Management
Requisitions RX Document
Presentation transcript:

Review Databases and Objects CCT395, Week 9 Review Databases and Objects Yuri Takhteyev University of Toronto November 3, 2010 This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/.

- Proposals & projects - Schedule & readings - The exam - Next class Announcements - Proposals & projects - Schedule & readings - The exam - Next class

João's Coffee

And there is probably more! The Entities Coffee shop Representative Shipper Estate Coffee Batch Warehouse Exchange Rate Invoice And there is probably more!

Divide and Conquer Grouping João's concerns: - Getting customers the right coffee - Tracking deliveries - Tracking money

Divide and Conquer Getting the customers the right coffee - Ordering the right coffee - Delivering the coffee to the right customers

The Coffee Estate name, description Region Variety Request quantity, what kind, who requested Shipment quantity, what kind of coffee

let's leave for later whose request it is Region Estate Variety ------------- name description Estate ------------- name description Variety ------------- name description Shipment ------------- quantity date ordered Request ------------- quantity date let's leave for later whose request it is

? Region Estate Variety Request Shipment ------------- name description Estate ------------- name description Variety ------------- name description ? Request ------------- quantity date Shipment ------------- quantity date ordered

Region Estate Variety Harvest Request Shipment ------------- name description Estate ------------- name description Variety ------------- name description Harvest ------------- year notes Request ------------- quantity date Shipment ------------- quantity date ordered

Region Estate Variety Harvest Request Shipment ------------- name* description Estate ------------- name* description Variety ------------- name* description Harvest ------------- year notes Request ------------- quantity date Shipment ------------- quantity date ordered

Region Estate Variety Harvest Request Shipment year notes ----------------- name description Estate ----------------- name description Variety ----------------- name description Harvest ----------------- year notes Request ----------------- quantity date Shipment ----------------- quantity date ordered

For those two we could consider using foreign keys as PKs Region ----------------- region_id* name description Estate ----------------- estate_id* name description For those two we could consider using foreign keys as PKs Variety ----------------- variety_id* name description Harvest ----------------- harvest_id* year notes Request ----------------- quantity date Shipment ----------------- shipment_id* quantity date ordered

No longer a pure ER diagram! Region ----------------- region_id* name description Estate ----------------- estate_id* region_id name description No longer a pure ER diagram! Variety ----------------- variety_id* name description Harvest ----------------- harvest_id* variety_id estate_id year notes Request ----------------- harvest_id shipment_id quantity date Shipment ----------------- shipment_id* quantity date ordered

A Relation harvest (harvest_id*, variety_id, estate_id, year, notes) harvest (harvest_id*, year, notes)

harvest ( harvest_id*, variety_id, estate_id, year, notes ) A Relation harvest ( harvest_id*, variety_id, estate_id, year, notes )

SQL create table harvest ( harvest_id int, variety_id int, foreign key (variety_id) references variety(variety_id), estate_id int, foreign key (estate_id) references estate(estate_id), year year, notes varchar(200), primary key (harvest_id), );

to be continued

Projects PHP Resources http://www.w3schools.com/php/default.asp the Menagerie Web example Get the database done first Do basic features before the advanced The 6th bullet point of section 2.2 is now optional Advanced features just do two Don't hesitate to ask questions!

Advanced Features Login Store the password in the database Ideally, use md5() to store a “hash” of a function Have the user enter a username and password Check what the user's password should be Compare this with what they entered If using md5(), compare the hashes. If you can, use PHP sessions to remember the user. Otherwise, just have them enter the password every time.

Advanced Features Enabling Modifications Do an INSERT or UPDATE based on the form data Backup mysqldump is the simplest option XML Output See examples from last week's class Make sure your XML validates: http://www.w3schools.com/xml/xml_validato r.asp

Advanced Features Transactions Chapter 13 in SQL – we are not covering this Stored Procedures SQL chapter 14. Again, we are not covering this Publicly Available Data I.e., using “real” data

Objects

Models Relational: - good for retrieval and updates Document: - good for exchange of data Objects: - good for active manipulation - good for changing software

“Need to know” basis (fewer assumptions → easier to make changes) Encapsulation “Need to know” basis (fewer assumptions → easier to make changes)

Region Estate Variety Harvest Request Shipment harvest_id* year notes ----------------- region_id* name description Estate ----------------- estate_id* region_id name description Variety ----------------- variety_id* name description Harvest ----------------- harvest_id* variety_id estate_id year notes Request ----------------- harvest_id shipment_id quantity date Shipment ----------------- shipment_id* quantity date ordered

Messages aka “methods” Harvest get_estate() set_estate() get_variety() ----------------- get_estate() set_estate() get_variety() set_variety() ...

The Implementation Harvest Estate estate variety year notes get_name() ----------------- estate variety year notes Estate ----------------- get_name() set_name() get_descript() set_descript() ...

Object-Oriented Programming (OOP) $harvest = $order->getHarvest(); $estate = $harvest->getEstate(); $estate->setName(“Boa Vista”); Harvest ----------------- get_estate() set_estate() get_variety() set_variety() ... Estate ----------------- get_name() set_name() get_descript() set_descript() ... Object-Oriented Programming (OOP)

PHP with MySQL Don't forge the PHP Tutorial: $query = "select name, species from pet where owner='" . $owner . "'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['species'] . "</td>"; echo "</tr>"; } Don't forge the PHP Tutorial: http://www.w3schools.com/php/default.asp

Updating the Data $query = "update pet set species='" . $species . "' where name='"; . $name . "'"; $result = mysql_query($query); echo "ok";

Select and Update $query = "select name, species from pet where owner='" . $owner . "'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $name = $row['name']; echo "Let's change the species of "; echo $name . " from " . $row['species']; echo " to " . $new_species; $update_query = "update pet set species='" . $new_species . "' where name='"; . $name . "'"; $update_result = mysql_query($query); }

What We Want $pets = $menagerie->get_pets_by_owner($owner); while ($pet = $pets->next()) { echo "Let's change the species of "; echo $pet->get_name() . " from " . $pet->get_species(); echo " to " . $new_species; $pet->set_name($new_species); $menagerie->save(); }

Or Even 1. Easier / more intuitive 2. Encapsulation simplifies reuse $pets = $menagerie->get_pets_by_owner($owner); while ($pet = $pets->next()) { echo "Let's change the species of "; echo $pet->name . " from " . $pet->species; echo " to " . $new_species; $pet->name = $new_species; $menagerie->save(); } 1. Easier / more intuitive 2. Encapsulation simplifies reuse Too good to be true?

Object-Relational Mapping Option 1: Map objects to relations (code → database) Option 2: Map relations to objects (database → code)

Option 2 Manual: We setup a mapping pet.name → getName($name) setName($name) Automatic: The software figures it out (“introspection”)

Examples Rails / ActiveRecord (Ruby) Django (Python) Hibernate (Java) Doctrine (PHP)

Questions?