1 ##################################################
4 # Purpose: To create a tpcb database using Disk Data,
5 # tables and stored procedures to load the database
6 # and run transactions against the DB
7 ##################################################
9 DROP DATABASE IF EXISTS tpcb;
14 eval CREATE
TABLE tpcb.account
15 (
id INT, bid INT, balance DECIMAL(10,2),
16 filler CHAR(255), PRIMARY
KEY(
id))
17 TABLESPACE $table_space STORAGE DISK
20 eval CREATE
TABLE tpcb.branch
21 (bid INT, balance DECIMAL(10,2), filler VARCHAR(255),
22 PRIMARY
KEY(bid))TABLESPACE $table_space STORAGE DISK
25 eval CREATE
TABLE tpcb.teller
26 (tid INT, balance DECIMAL(10,2), filler VARCHAR(255),
27 PRIMARY
KEY(tid)) TABLESPACE $table_space STORAGE DISK
31 eval CREATE
TABLE tpcb.history
32 (
id MEDIUMINT NOT NULL AUTO_INCREMENT,aid INT,
33 tid INT, bid INT, amount DECIMAL(10,2),
34 tdate DATETIME, teller CHAR(20), uuidf LONGBLOB,
35 filler CHAR(80),PRIMARY
KEY (
id))
36 TABLESPACE $table_space STORAGE DISK
40 --echo --- Create stored procedures & functions ---
45 CREATE PROCEDURE tpcb.load()
47 DECLARE acct INT DEFAULT 100;
48 DECLARE brch INT DEFAULT 10;
49 DECLARE tell INT DEFAULT 100;
50 DECLARE tmp INT DEFAULT 10;
54 INSERT INTO tpcb.account VALUES (acct, brch, 0.0,
"FRESH ACCOUNT");
58 INSERT INTO tpcb.branch VALUES (brch, 0.0,
"FRESH BRANCH");
62 INSERT INTO tpcb.teller VALUES (tell, 0.0,
"FRESH TELLER");
67 CREATE FUNCTION tpcb.account_id () RETURNS INT
71 SELECT RAND() * 10 INTO ran;
74 SELECT RAND() * 10 INTO num;
76 SELECT RAND() * 100 INTO num;
85 CREATE FUNCTION tpcb.teller_id () RETURNS INT
89 SELECT RAND() * 10 INTO ran;
92 SELECT RAND() * 10 INTO num;
94 SELECT RAND() * 100 INTO num;
103 CREATE PROCEDURE tpcb.trans(in format varchar(3))
105 DECLARE acct INT DEFAULT 0;
106 DECLARE brch INT DEFAULT 0;
107 DECLARE tell INT DEFAULT 0;
108 DECLARE bal DECIMAL(10,2) DEFAULT 0.0;
109 DECLARE amount DECIMAL(10,2) DEFAULT 1.00;
110 DECLARE
test INT DEFAULT 0;
111 DECLARE bbal DECIMAL(10,2) DEFAULT 0.0;
112 DECLARE tbal DECIMAL(10,2) DEFAULT 0.0;
113 DECLARE local_uuid VARCHAR(255);
114 DECLARE local_user VARCHAR(255);
115 DECLARE local_time TIMESTAMP;
117 SELECT RAND() * 10 INTO
test;
118 SELECT tpcb.account_id() INTO acct;
119 SELECT tpcb.teller_id() INTO tell;
121 SELECT account.balance INTO bal FROM tpcb.account WHERE
id = acct;
122 SELECT account.bid INTO brch FROM tpcb.account WHERE
id = acct;
123 SELECT teller.balance INTO tbal FROM tpcb.teller WHERE tid = tell;
124 SELECT branch.balance INTO bbal FROM tpcb.branch WHERE bid = brch;
128 SET bal = bal + amount;
129 SET bbal = bbal + amount;
130 SET tbal = tbal + amount;
131 UPDATE tpcb.account SET balance = bal, filler = 'account updated'
133 UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
135 UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
138 SET bal = bal - amount;
139 SET bbal = bbal - amount;
140 SET tbal = tbal - amount;
141 UPDATE tpcb.account SET balance = bal, filler = 'account updated'
143 UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
145 UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
151 SET local_uuid=UUID();
152 SET local_user=USER();
153 SET local_time= NOW();
154 INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, local_time,local_user,
155 local_uuid,'completed trans');
157 INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, NOW(), USER(),
158 UUID(),'completed trans');
164 --echo *** Stored Procedures Created ***