-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctions.sql
More file actions
82 lines (67 loc) · 2.07 KB
/
Copy pathFunctions.sql
File metadata and controls
82 lines (67 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Functions
CREATE OR REPLACE FUNCTION new_Author(AuthorfirstName varchar(255), AuthorLastName varchar(255))
RETURNS integer AS
$BODY$
DECLARE
v_id integer;
BEGIN
--Inserts a new author
INSERT INTO Author(AuthorfirstName, AuthorLastName)
VALUES (AuthorfirstName, AuthorLastName)
RETURNING Author_id INTO v_id
-- Return the new id and use in a select clause
RETURN v_id;
END;
$BODY$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION new_Publisher
(
AccountName VARCHAR(255),
CardNumber VARCHAR(255),
AccountType VARCHAR (20),
PublisherName VARCHAR(255),
Address VARCHAR(255),
Email VARCHAR (100),
PhoneNumber VARCHAR (255)
)
RETURNS integer AS
$BODY$
CREATE OR REPLACE FUNCTION new_Book(
BookName VARCHAR(255),
Author_id INT,
ISBN VARCHAR(100),
Genre VARCHAR(255),
NumberOfPages INT,
Price NUMERIC(5,2),
Publisher_id INT
)
CREATE OR REPLACE FUNCTION new_BookUser
(
AccountName VARCHAR(255),
CardNumber VARCHAR(255),
AccountType VARCHAR (20),
UserPassword VARCHAR(255),
UserName VARCHAR(255),
UserEmail VARCHAR(255),
ShippingAddress VARCHAR(255),
BillingAddress VARCHAR(255),
CreditCardInfo VARCHAR(255)
)
v_account_id integer;
v_bookuser_id integer;
BEGIN
-- Inserts the new Account record and retrieves the last inserted id
INSERT INTO Account(AccountName, CardNumber, AccountType)
VALUES (AccountName, CardNumber, AccountType)
-- Inserts the new Publisher record and retrieves the last inserted id
INSERT INTO BookUser(account_id, userpassword, username, useremail, shippingaddress, billingaddress, creditcardinfo)
VALUES (v_account_id, userpassword, username, useremail, shippingaddress, billingaddress, creditcardinfo)
CREATE OR REPLACE FUNCTION new_Order( BookUser_id INT)
RETURNS integer AS
$BODY$
DECLARE
v_id integer;
BEGIN
-- Inserts the new Order record and retrieves the last inserted id
INSERT INTO Bookorder(BookUser_id)
VALUES (BookUser_id)