Hi All
With stored procedures, functions, triggers ... more and more code can
now be written in SQL when developing an application.
For applications with a significant amount of code written in any
language, developers tends to need tools to deal with the code
itself, like gcov (code coverage for gcc), gprof (performance monitoring
for gcc), etc.
What if MySQL, given the following SQL code :
cat mysql-test/t/cov_gcov_if.sql
delimiter ;;
#line 4
create function fct_if(x char(20), y char(20))
returns char(20)
begin
declare result char(20);
if (x < y)
then
set result = "lower";
else
set result = "not lower";
end if;
return result;
end ;;
and after executing that statement at runtime :
select fct_if("xx", "yy");
could generate SQL code coverage data, like this (in case of poor
formating, see the attached file)
$ gcov t/cov_gcov_if.sql
File `./t/cov_gcov_if.sql'
Lines executed:80.00% of 5
./t/cov_gcov_if.sql:creating `cov_gcov_if.sql.gcov'
-: 0:Source:./t/cov_gcov_if.sql
-: 0:Graph:cov_gcov_if.gcno
-: 0:Data:cov_gcov_if.gcda
-: 0:Runs:0
-: 0:Programs:1
-: 1:delimiter ;;
-: 2:
-: 3:#line 4
function test.fct_if called 1 returned 100% blocks executed 67%
-: 4:create function fct_if(x char(20), y char(20))
-: 5:returns char(20)
-: 6:begin
1: 7: declare result char(20);
1: 8: if (x < y)
-: 9: then
1: 10: set result = "lower";
-: 11: else
#####: 12: set result = "not lower";
-: 13: end if;
1: 14: return result;
-: 15:end ;;
-: 16:
Do you think having code coverage in the procedural MySQL code itself
would be of interest for a developer ?
Note that the following example is not forged, but an actual result from
a prototype
I have been working on for a while.
The way the code is fed to the server is :
cpp ./t/cov_gcov_if.sql | mysql --enable-comments
which happen to have the "strange" property of :
- generating special '#' comments, like #line "file" comments (cpp)
- preserving these comments and send them to the server (mysql
--enable-comments),
which is a patch I posted earlier.
The code on the server contains "instrumentation" code in the parser and
"sp_*" area,
which collects the data needed.
Before discussing the full patch itself (it's only a prototype and still
need some work,
not to mention has a few thousands lines of code),
I would appreciate your thoughts on the functionality itself.
Regards,
Marc Alff.
Attachment: [text/html]
Attachment: [text/html]
-: 0:Source:./t/cov_gcov_if.sql
-: 0:Graph:cov_gcov_if.gcno
-: 0:Data:cov_gcov_if.gcda
-: 0:Runs:0
-: 0:Programs:1
-: 1:delimiter ;;
-: 2:
-: 3:#line 4
function test.fct_if called 1 returned 100% blocks executed 67%
-: 4:create function fct_if(x char(20), y char(20))
-: 5:returns char(20)
-: 6:begin
1: 7: declare result char(20);
1: 8: if (x < y)
-: 9: then
1: 10: set result = "lower";
-: 11: else
#####: 12: set result = "not lower";
-: 13: end if;
1: 14: return result;
-: 15:end ;;
-: 16: