0% found this document useful (0 votes)
24 views20 pages

Lab 15

This document describes a lab activity involving database implementation. The key steps covered include: 1) Setting up MySQL and creating a database and table. 2) Connecting to the database from Python and inserting records. 3) Creating stored procedures and functions to authenticate users from the login application. 4) Repeating the process using Microsoft SQL Server Management Studio instead of MySQL. Supplementary activities included creating a GUI application to interact with the database and stored procedures.

Uploaded by

Cassie Cutie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views20 pages

Lab 15

This document describes a lab activity involving database implementation. The key steps covered include: 1) Setting up MySQL and creating a database and table. 2) Connecting to the database from Python and inserting records. 3) Creating stored procedures and functions to authenticate users from the login application. 4) Repeating the process using Microsoft SQL Server Management Studio instead of MySQL. Supplementary activities included creating a GUI application to interact with the database and stored procedures.

Uploaded by

Cassie Cutie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Lab Activity #15- Database Implementation

Gerandoy, Glen John E. 10/07/2019


Course/Section: CPE011-CPE21FB3 Engr. Royce B. Chua

Database Output:
I. Initial Setup
1. Ensure that the MySQL service is running through XAMPP.

-Before starting, I open the XAMPP and click start in Mysql so that it will
connect to the database.

2. Create a new database mydb_<lastname> with the table Accounts


using SQL Commands. Accounts table should contain: id, username,
password. Note: id and username should be unique.
-After starting MySql, I created a new database in workbench named
mydb_dizon.

-After creating the database, I inserted a table to it named accounts with its
primary key.
3. Insert at least 2 records into the Accounts table.

-The table is successfully added to the database, and I inserted two values to
it.
. 4. Open your Python editor and copy the following code to your program
and then run/execute the program shown below:
-This is the code copied from the module.
5. The connection should be established successfully.

-After executing the code, it is printed that the connection successfully


established.

II. Executing SQL and Stored Procedures


A. Creating the SQLDBConnector
1. Create a SQLDBConnector.py file in your workspace folder.
2. Type the following source codes to the SQLDBConnector.py.
3. Save the changes to the file.
-This is the copied code form the module, I also saved it as
SQLDBconnector.py.
B. Creating the Login Window
1. Create a login.py file in the same workspace folder.
2. Type the following source codes to the SQLDBConnector.py.
Note: You will need to replace the SQLDBConnector object parameters for a
successful connection.

3. Save the changes to the file and run using the Python editor or the
command prompt.
4. The output should appear similar to the image below.
-After doing the required task this is the GUI created.

5. Enter a username and password that matches records in the created


Accounts table. The output should look similar to the one below.

-I tried to fill the text box and use the username and password that I inserted
in the table accounts. As you can see after logging-in the user is successfully
validated.
You may use one of the two accounts instructed to be created earlier in the
activity. Both of them should be successfully validated.
6. Enter a username and password that does not match a record in the
created Accounts table. The output should look similar to the one below.

-This is the result when the username and password is nit inserted in table
accounts of the database mydb_dizon.A message box shows that user
validation failed.

C. Executing Stored Function / Stored Procedures


1. Using the MySQL Workbench query editor or the Command Terminal,
copy the following code below.
-In this figure, I created a function in the database where 1 states that the
username is log-in while 0 states that the username is not in the account or
failed to log-in.

-After doing the code, this is successfully applied and created.

2. Execute the SQL code.


3. Using the MySQL Workbench query editor or the Command Terminal,
copy the following code below.

-After creating new function, I used it in create procedure.

-After executing the query, this is successfully applied on the LoginUser that
I created.

4. Execute the SQL code.


5. Test the Stored Procedure and Function by copying the following code
and executing it.
-After creating the procedure and function, I call the LoginUser that is
successfully added on the database. And use the username and password
that is inserted in the account tabel. On the right side of the screenshot the
result shows that the username pat is logged-in.

-This is the result of successfully call for loginuser.


7. Modify the login.py code by replacing the codes in the Python function
authenticateUser() with the code below. The ones emphasized with red
lines are the codes that were changed.

-In this figure, I call the procedure


that I created in workbench.

8. Run login.py and validate the result again. The output should be the same
with procedures 5 and 6.
MS SQL Database Connection
1. Login to the SQL Server Management Studio using your credentials.
2. Create the database mydb_<lastname>.

-In Microsoft SQL, I created a same database named mydb_dizon. And it is


successfully added.

3. Create the Accounts table and insert at least two values to the table.
-Inserted a new table named accounts.

-This is the values from the account table.

5. Create the scalar-valued stored function named authenticateUser.


-In this figure, I created scalar-value function named Authenticate User.

6. Create the stored procedure login.


-This is a new stored procedure and I call the function that I created
previously. It is successfully completed.

7. Test the stored procedure and function.

-This is the result after executing the command, it is different from the result
that I get in SQL workbench.
8. The result of the login_status should be similar earlier on the MySQL.
9. Modify the SQLDBConnector.py with the code below

SUPPLEMENTARY ACTIVITY
Do the following tasks and copy screenshot(s) of your output using Microsoft
SQL Server Management Studio.

1. The database that will be used is the ABCLibrary database. You may
use an existing ABCLibary database or create a new one.

-In this figure, I created a database ABCLibrary and inserted new tables to it
that can be used later on. These tables are book, customers, and book order.

2. Create a GUI application that can insert, delete and modify the book
information in ABCLibrary Database.
-This is the main window from the GUI that I created.

-This the GUI when you insert record to the abc library.
3. Create stored procedures that can insert, delete and modify the book
information using the book table in ABCLibrary database.
4. Call the stored procedures from your book information.
------------------------------------------------------------------------------------------------------------
---------
SUMMARY:
The topics that were discussed in this activity lab are:
 Use of host
 Use of port
 Use of db in mysql
 Use of user in mysql
 Use of password even if it is optional
 Use stored procedure, function and trigger inside a program.
 Connecting mysql and ssms into an application or program
 Difference between SSMS vs MySQL
CONLCUSION:
In this lab activity I conclude that SSMS is better than MySQL because
some parts in MySQL are limited like the stored function, in MySQL you can
only use scalar function while in SSMS you can use Inline single table, multi-
line table and scalar function.

RECOMMENDATION:
I recommend to use SSMS than MySQL because if you’re going to
make an application or program that shows table or uses table it’s better to
use SSMS.
LESSON LEARNED:
In this laboratory activity I learned:
 Use of host
 Use of port
 Use of db in mysql
 Use of user in mysql
 Use of password even if it is optional
 Use stored procedure, function and trigger inside a program.
 Connecting mysql and ssms into an application or program
 Difference between SSMS vs MySQL

You might also like