##################################################
# Author: Jeb
# Date: 2007/05
# Purpose: To create a tpcb database using Disk Data,
# tables and stored procedures to load the database
# and run transactions against the DB
##################################################
--disable_warnings
DROP DATABASE IF EXISTS tpcb;
--enable_warnings
CREATE DATABASE tpcb;
--disable_query_log
delimiter |;
CREATE PROCEDURE tpcb.load() BEGIN
DECLARE acct INT DEFAULT 100;
DECLARE brch INT DEFAULT 10;
DECLARE tell INT DEFAULT 100;
DECLARE tmp INT DEFAULT 10; WHILE brch > 0DO SET tmp = 100; WHILE tmp > 0DO
INSERT INTO tpcb.account VALUES (acct, brch, 0.0, "FRESH ACCOUNT"); SET acct = acct - 1; SET tmp = tmp -1; ENDWHILE;
INSERT INTO tpcb.branch VALUES (brch, 0.0, "FRESH BRANCH"); SET brch = brch - 1; ENDWHILE; WHILE tell > 0DO
INSERT INTO tpcb.teller VALUES (tell, 0.0, "FRESH TELLER"); SET tell = tell - 1; ENDWHILE; END|
CREATE FUNCTION tpcb.account_id () RETURNS INT BEGIN
DECLARE num INT;
DECLARE ran INT;
SELECT RAND() * 10 INTO ran; IF (ran < 5) THEN
SELECT RAND() * 10 INTO num; ELSE
SELECT RAND() * 100 INTO num; ENDIF; IF (num < 1) THEN
RETURN 1; ENDIF;
RETURN num; END|
CREATE FUNCTION tpcb.teller_id () RETURNS INT BEGIN
DECLARE num INT;
DECLARE ran INT;
SELECT RAND() * 10 INTO ran; IF (ran < 5) THEN
SELECT RAND() * 10 INTO num; ELSE
SELECT RAND() * 100 INTO num; ENDIF; IF (num < 1) THEN
RETURN 1; ENDIF;
RETURN num; END|
CREATE PROCEDURE tpcb.trans(in format varchar(3)) BEGIN
DECLARE acct INT DEFAULT 0;
DECLARE brch INT DEFAULT 0;
DECLARE tell INT DEFAULT 0;
DECLARE bal DECIMAL(10,2) DEFAULT 0.0;
DECLARE amount DECIMAL(10,2) DEFAULT 1.00;
DECLARE test INT DEFAULT 0;
DECLARE bbal DECIMAL(10,2) DEFAULT 0.0;
DECLARE tbal DECIMAL(10,2) DEFAULT 0.0;
DECLARE local_uuid VARCHAR(255);
DECLARE local_user VARCHAR(255);
DECLARE local_time TIMESTAMP;
SELECT RAND() * 10 INTO test;
SELECT tpcb.account_id() INTO acct;
SELECT tpcb.teller_id() INTO tell;
SELECT account.balance INTO bal FROM tpcb.account WHERE id = acct;
SELECT account.bid INTO brch FROM tpcb.account WHERE id = acct;
SELECT teller.balance INTO tbal FROM tpcb.teller WHERE tid = tell;
SELECT branch.balance INTO bbal FROM tpcb.branch WHERE bid = brch;
IF (test < 5) THEN SET bal = bal + amount; SET bbal = bbal + amount; SET tbal = tbal + amount;
UPDATE tpcb.account SET balance = bal, filler = 'account updated'
WHERE id = acct;
UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
WHERE bid = brch;
UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
WHERE tid = tell; ELSE SET bal = bal - amount; SET bbal = bbal - amount; SET tbal = tbal - amount;
UPDATE tpcb.account SET balance = bal, filler = 'account updated'
WHERE id = acct;
UPDATE tpcb.branch SET balance = bbal, filler = 'branch updated'
WHERE bid = brch;
UPDATE tpcb.teller SET balance = tbal, filler = 'teller updated'
WHERE tid = tell; ENDIF;
IF (format = 'SBR') THEN SET local_uuid=UUID(); SET local_user=USER(); SET local_time= NOW();
INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, local_time,local_user,
local_uuid,'completed trans'); ELSE
INSERT INTO tpcb.history VALUES(NULL,acct,tell,brch,amount, NOW(), USER(),
UUID(),'completed trans'); ENDIF; END|
delimiter ;|
--enable_query_log
--echo
--echo *** Stored Procedures Created ***
--echo
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.