Skip to content

Commit 80e470f

Browse files
committed
Completed Demos and Examples
1 parent 4c4fb74 commit 80e470f

File tree

5 files changed

+229
-11
lines changed

5 files changed

+229
-11
lines changed

docs/demo/README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,19 @@ Note: This ad-hoc test also demonstrates implicit data type conversion.
7979
A test runner package is central to running tests in wtPLSQL. The [Test Runner](Test-Runner.md) page covers all the basics of creating a test runner package.
8080

8181
## Database Object Tests
82-
More interesting examples actually test database objects. Here is an example test of each database object supported by wtPLSQL.
82+
More interesting examples actually test database objects. Here are some examples.
8383
* [Package Test](Package-Test.md)
84-
* Procedure Test
85-
* Function Test
8684
* [Table Constraints Test](Table-Test.md)
8785
* [Trigger Test](Trigger-Test.md)
8886
* [Type Test](Type-Test.md)
8987

9088
## utPLSQL 2.3 Examples
91-
* ut_calc_secs_between - Test a Simple Procedure
92-
* ut_truncit - Test a Table Modification Procedure
93-
* ut_str - Test a Simple Function
94-
* ut_del1 - Test an Entire Package
95-
* Create and Run a Test Suite - Build a Test Suite package.
96-
* ut_betwnstr
97-
* Version
89+
wtPLSQL was built with the utPLSQL "ut_assert" API. These examples were created from the original utPLSQL 2.3 examples without modifying the "ut_assert" calls
90+
91+
* [ut_betwnstr](https://utplsql.org/utPLSQL/v2.3.1/fourstep.html) - Choose a program to test
92+
* [ut_calc_secs_between](https://utplsql.org/utPLSQL/v2.3.1/testproc.html) - Test a Simple Procedure
93+
* [ut_truncit](https://utplsql.org/utPLSQL/v2.3.1/testproc.html) - Test a Table Modification Procedure
94+
* [ut_str](https://utplsql.org/utPLSQL/v2.3.1/testfunc.html) - Test a Simple Function
9895

9996
---
10097
[Website Home Page](../README.md)

src/demo/ut_betwnstr.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@ end wtplsql_run;
8181

8282
end ut_betwnstr;
8383
/
84+
85+
set serveroutput on size unlimited format word_wrapped
86+
87+
begin
88+
wtplsql.test_run('UT_BETWNSTR');
89+
wt_text_report.dbms_out(in_runner_name => 'UT_BETWNSTR'
90+
,in_detail_level => 30);
91+
end;
92+
/

src/demo/ut_calc_secs_between.sql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ BEGIN
6161
END wtplsql_run;
6262

6363
END ut_calc_secs_between;
64-
/
64+
/
65+
66+
set serveroutput on size unlimited format word_wrapped
67+
68+
begin
69+
wtplsql.test_run('UT_CALC_SECS_BETWEEN');
70+
wt_text_report.dbms_out(in_runner_name => 'UT_CALC_SECS_BETWEEN'
71+
,in_detail_level => 30);
72+
end;
73+
/

src/demo/ut_str.sql

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
/* Formatted on 2001/11/19 15:11 (Formatter Plus v4.5.2) */
3+
CREATE OR REPLACE PACKAGE str
4+
IS
5+
FUNCTION betwn (
6+
string_in IN VARCHAR2,
7+
start_in IN PLS_INTEGER,
8+
end_in IN PLS_INTEGER
9+
)
10+
RETURN VARCHAR2;
11+
12+
FUNCTION betwn2 (
13+
string_in IN VARCHAR2,
14+
start_in IN PLS_INTEGER,
15+
end_in IN PLS_INTEGER
16+
)
17+
RETURN VARCHAR2;
18+
19+
PROCEDURE wtplsql_run;
20+
END str;
21+
/
22+
23+
/* Formatted on 2001/11/19 15:15 (Formatter Plus v4.5.2) */
24+
CREATE OR REPLACE PACKAGE BODY str
25+
IS
26+
FUNCTION betwn (
27+
string_in IN VARCHAR2,
28+
start_in IN PLS_INTEGER,
29+
end_in IN PLS_INTEGER
30+
)
31+
RETURN VARCHAR2
32+
IS
33+
l_start PLS_INTEGER := start_in;
34+
BEGIN
35+
IF l_start = 0
36+
THEN
37+
l_start := 1;
38+
END IF;
39+
40+
RETURN (SUBSTR (
41+
string_in,
42+
l_start,
43+
end_in
44+
- l_start
45+
+ 1
46+
)
47+
);
48+
END;
49+
50+
FUNCTION betwn2 (
51+
string_in IN VARCHAR2,
52+
start_in IN PLS_INTEGER,
53+
end_in IN PLS_INTEGER
54+
)
55+
RETURN VARCHAR2
56+
IS
57+
BEGIN
58+
-- Handle negative values
59+
IF end_in < 0
60+
THEN
61+
RETURN betwn (string_in, start_in, end_in);
62+
ELSE
63+
RETURN (SUBSTR (
64+
string_in,
65+
LENGTH (string_in)
66+
+ end_in
67+
+ 1,
68+
start_in
69+
- end_in
70+
+ 1
71+
)
72+
);
73+
END IF;
74+
END;
75+
76+
--%WTPLSQL_begin_ignore_lines%--
77+
78+
-- For each program to test...
79+
PROCEDURE ut_betwn
80+
IS
81+
BEGIN
82+
utassert.eq (
83+
'Typical Valid Usage',
84+
str.betwn ('this is a string', 3, 7),
85+
'is is'
86+
);
87+
utassert.eq (
88+
'Test Negative Start',
89+
str.betwn ('this is a string', -3, 7),
90+
'ing'
91+
);
92+
utassert.isnull (
93+
'Start bigger than end',
94+
str.betwn ('this is a string', 3, 1)
95+
);
96+
END;
97+
98+
--% WTPLSQL SET DBOUT "STR:PACKAGE BODY" %--
99+
PROCEDURE wtplsql_run IS
100+
BEGIN
101+
ut_betwn;
102+
END wtplsql_run;
103+
104+
END str;
105+
/
106+
107+
set serveroutput on size unlimited format word_wrapped
108+
109+
begin
110+
wtplsql.test_run('STR');
111+
wt_text_report.dbms_out(in_runner_name => 'STR'
112+
,in_detail_level => 30);
113+
end;
114+
/

src/demo/ut_truncit.sql

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
/*file truncit.sp */
3+
CREATE OR REPLACE PROCEDURE truncit (
4+
tab IN VARCHAR2,
5+
sch IN VARCHAR2 := NULL
6+
)
7+
IS
8+
BEGIN
9+
EXECUTE IMMEDIATE 'truncate table ' || NVL (sch, USER) || '.' || tab;
10+
END;
11+
/
12+
13+
/*file tabcount.sf */
14+
CREATE OR REPLACE FUNCTION tabcount (
15+
sch IN VARCHAR2,
16+
tab IN VARCHAR2)
17+
RETURN INTEGER
18+
IS
19+
retval INTEGER;
20+
BEGIN
21+
EXECUTE IMMEDIATE
22+
'SELECT COUNT(*) FROM ' || sch || '.' || tab
23+
INTO retval;
24+
RETURN retval;
25+
EXCEPTION
26+
WHEN OTHERS
27+
THEN
28+
RETURN NULL;
29+
END;
30+
/
31+
32+
CREATE OR REPLACE PACKAGE ut_truncit
33+
IS
34+
PROCEDURE wtplsql_run;
35+
END ut_truncit;
36+
/
37+
38+
/*file ut_truncit.pkb */
39+
CREATE OR REPLACE PACKAGE BODY ut_truncit
40+
IS
41+
PROCEDURE ut_setup
42+
IS
43+
BEGIN
44+
EXECUTE IMMEDIATE
45+
'CREATE TABLE temp_emp AS SELECT * FROM DUAL';
46+
END;
47+
48+
PROCEDURE ut_teardown
49+
IS
50+
BEGIN
51+
EXECUTE IMMEDIATE
52+
'DROP TABLE temp_emp';
53+
END;
54+
55+
-- For each program to test...
56+
PROCEDURE ut_TRUNCIT IS
57+
BEGIN
58+
TRUNCIT (
59+
TAB => 'temp_emp'
60+
,
61+
SCH => USER
62+
);
63+
64+
utAssert.eq (
65+
'Test of TRUNCIT',
66+
tabcount (USER, 'temp_emp'),
67+
0
68+
);
69+
END ut_TRUNCIT;
70+
71+
--% WTPLSQL SET DBOUT "TRUNCIT:PROCEDURE" %--
72+
73+
PROCEDURE wtplsql_run IS
74+
BEGIN
75+
ut_setup;
76+
ut_TRUNCIT;
77+
ut_teardown;
78+
END wtplsql_run;
79+
END ut_truncit;
80+
/
81+
82+
set serveroutput on size unlimited format word_wrapped
83+
84+
begin
85+
wtplsql.test_run('UT_TRUNCIT');
86+
wt_text_report.dbms_out(in_runner_name => 'UT_TRUNCIT'
87+
,in_detail_level => 30);
88+
end;
89+
/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy