1 ##################################################
4 # Purpose: To create a tpcb database, tables and
5 # stored procedures to load the database
6 # and run transactions against the DB
7 ##################################################
9 DROP DATABASE IF EXISTS tpcb;
14 CREATE
TABLE tpcb.account (
id INT, bid INT, balance DECIMAL(10,2),
15 filler CHAR(255), PRIMARY
KEY(
id));
17 CREATE
TABLE tpcb.branch (bid INT, balance DECIMAL(10,2), filler VARCHAR(255),
20 CREATE
TABLE tpcb.teller (tid INT, balance DECIMAL(10,2), filler VARCHAR(255),
23 CREATE
TABLE tpcb.history (
id MEDIUMINT NOT NULL AUTO_INCREMENT,aid INT,
24 tid INT, bid INT, amount DECIMAL(10,2),
25 tdate DATETIME, teller CHAR(20), uuidf LONGBLOB,
26 filler CHAR(80),PRIMARY
KEY (
id));
29 --echo --- Create stored procedures & functions ---
34 CREATE PROCEDURE tpcb.load()
36 DECLARE acct INT DEFAULT 100;
37 DECLARE brch INT DEFAULT 10;
38 DECLARE tell INT DEFAULT 100;
39 DECLARE tmp INT DEFAULT 10;
43 INSERT INTO tpcb.account VALUES (acct, brch, 0.0,
"FRESH ACCOUNT");
47 INSERT INTO tpcb.branch VALUES (brch, 0.0,
"FRESH BRANCH");
51 INSERT INTO tpcb.teller VALUES (tell, 0.0,
"FRESH TELLER");
56 CREATE FUNCTION tpcb.account_id () RETURNS INT
60 SELECT RAND() * 10 INTO ran;
63 SELECT RAND() * 10 INTO num;
65 SELECT RAND() * 100 INTO num;
74 CREATE FUNCTION tpcb.teller_id () RETURNS INT
78 SELECT RAND() * 10 INTO ran;
81 SELECT RAND() * 10 INTO num;
83 SELECT RAND() * 100 INTO num;
92 CREATE PROCEDURE tpcb.trans(in format varchar(3))
94 DECLARE acct INT DEFAULT 0;
95 DECLARE brch INT DEFAULT 0;
96 DECLARE tell INT DEFAULT 0;
97 DECLARE bal DECIMAL(10,2) DEFAULT 0.0;
98 DECLARE amount DECIMAL(10,2) DEFAULT 1.00;
99 DECLARE
test INT DEFAULT 0;
100 DECLARE bbal DECIMAL(10,2) DEFAULT 0.0;
101 DECLARE tbal DECIMAL(10,2) DEFAULT 0.0;
102 DECLARE local_uuid VARCHAR(255);
103 DECLARE local_user VARCHAR(255);
104 DECLARE local_time TIMESTAMP;
106 SELECT RAND() * 10 INTO
test;
107 SELECT tpcb.account_id() INTO acct;
108 SELECT tpcb.teller_id() INTO tell;
110 SELECT account.balance INTO bal FROM tpcb.account WHERE
id = acct;
111 SELECT account.bid INTO brch FROM tpcb.account WHERE
id = acct;
112 SELECT teller.balance INTO tbal FROM tpcb.teller WHERE tid = tell;
113 SELECT branch.balance INTO bbal FROM tpcb.branch WHERE bid = brch;
117 SET bal = bal + amount;
118 SET bbal = bbal + amount;
119 SET tbal = tbal + amount;
120 UPDATE tpcb.account SET balance = bal, filler = 'account updated'
122 UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
124 UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
127 SET bal = bal - amount;
128 SET bbal = bbal - amount;
129 SET tbal = tbal - amount;
130 UPDATE tpcb.account SET balance = bal, filler = 'account updated'
132 UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
134 UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
140 SET local_uuid=UUID();
141 SET local_user=USER();
142 SET local_time= NOW();
143 INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, local_time,local_user,
144 local_uuid,'completed trans');
146 INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, NOW(), USER(),
147 UUID(),'completed trans');
153 --echo *** Stored Procedures Created ***