Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
af49c477
Commit
af49c477
authored
13 years ago
by
Laurent Gil
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug with the character ` in the input file
parent
27304384
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/sql2html.pl
+71
-84
71 additions, 84 deletions
misc-scripts/sql2html.pl
with
71 additions
and
84 deletions
misc-scripts/sql2html.pl
+
71
−
84
View file @
af49c477
...
...
@@ -190,7 +190,6 @@ my @header_names = ('default');
my
@colours
=
(
$default_colour
);
my
%legend
;
my
$in_doc
=
0
;
my
$in_table
=
0
;
my
$header
=
'
default
';
...
...
@@ -204,6 +203,7 @@ my $display = 'Show';
my
$parenth_count
=
0
;
my
$header_colour
;
#############
## Parser ##
#############
...
...
@@ -216,20 +216,19 @@ while (<SQLFILE>) {
# Verifications
if
(
$_
=~
/^\/\*\*/
)
{
$in_doc
=
1
;
next
;
}
# start of a table documentation
if
(
$_
=~
/^\s*create\s+table\s+(if\s+not\s+exists\s+)?(\w+)/i
)
{
# start to parse the content of the table
my
$sql_t_name
=
remove_char
(
$
2
);
if
(
$sql_t_name
eq
$table
)
{
if
(
$_
=~
/^\s*create\s+table\s+(if\s+not\s+exists\s+)?`?(\w+)`?/i
)
{
# start to parse the content of the table
if
(
$table
eq
$
2
)
{
$in_table
=
1
;
$parenth_count
++
;
}
else
{
print
STDERR
"
The documentation of the table
$
sql_t_name
has not be found!
\n
";
print
STDERR
"
The documentation of the table $
2
has not be found!
\n
";
}
next
;
}
next
if
(
$in_doc
==
0
and
$in_table
==
0
);
my
$doc
=
$_
;
my
$doc
=
remove_char
(
$_
)
;
## Parsing of the documentation ##
if
(
$in_doc
==
1
)
{
...
...
@@ -284,30 +283,24 @@ while (<SQLFILE>) {
}
}
## Parsing of the SQL table to fetch the columns types ##
elsif
(
$in_table
==
1
)
{
#END OF TABLE DEFINITION
#Can't do this easily with a simply regex as there are varying valid formats
#The end of the table definition is actually defined by 2nd enclosing bracket
#
END OF TABLE DEFINITION
#
Can't do this easily with a simply regex as there are varying valid formats
#
The end of the table definition is actually defined by 2nd enclosing bracket
#Regex counting VOODOO!
#This basically puts the regex in a list context
#before inc/dec'ing with it in a scalar context.
#
Regex counting VOODOO!
#
This basically puts the regex in a list context
#
before inc/dec'ing with it in a scalar context.
$parenth_count
+=
()
=
$doc
=~
/\(/gi
;
$parenth_count
-=
()
=
$doc
=~
/\)/gi
;
# warn "parenth count is $parenth_count";
if
(
$parenth_count
==
0
)
{
# End of the sql table definition
if
(
scalar
@
{
$documentation
->
{
$header
}{'
tables
'}{
$table
}{
column
}}
>
$count_sql_col
)
{
#use Data::Dumper;
#warn "col count $count_sql_col";
#warn Data::Dumper::Dumper(\$documentation);
print
STDERR
"
Description of a non existant column in the table
$table
!
\n
";
print
STDERR
"
Description of a non existant column in the table
$table
!
\n
";
}
$in_table
=
0
;
...
...
@@ -317,73 +310,69 @@ while (<SQLFILE>) {
}
else
{
# warn "Processing table";
## INDEXES ##
if
(
$doc
=~
/^\s*(primary\s+key)\s*\((.+)\)/i
or
$doc
=~
/^\s*(unique)\s*\((.+)\)/i
){
# Primary or unique
my
$icol
=
remove_char
(
$
2
);
add_column_index
(
$
1
,
$icol
);
next
;
}
elsif
(
$doc
=~
/^\s*(unique\s+)?(key|index)\s+(\S+)\s*\((.+)\)/i
)
{
# Keys and indexes
my
$icol
=
remove_char
(
$
4
);
add_column_index
("
$1$2
",
$icol
,
$
3
);
next
;
}
elsif
(
$doc
=~
/^\s*(key)\s+\((.+)\)/i
)
{
# Keys
my
$icol
=
remove_char
(
$
2
);
add_column_index
("
$1
",
$icol
,'');
next
;
}
## TYPES & DEFAULT VALUES ##
my
$col_name
=
'';
my
$col_type
=
'';
my
$col_def
=
'';
## INDEXES ##
if
(
$doc
=~
/^\s*(primary\s+key)\s*\((.+)\)/i
or
$doc
=~
/^\s*(unique)\s*\((.+)\)/i
){
# Primary or unique;
add_column_index
(
$
1
,
$
2
);
next
;
}
elsif
(
$doc
=~
/^\s*(unique\s+)?(key|index)\s+(\S+)\s*\((.+)\)/i
)
{
# Keys and indexes
add_column_index
("
$1$2
",
$
4
,
$
3
);
next
;
}
elsif
(
$doc
=~
/^\s*(key)\s+\((.+)\)/i
)
{
# Keys
add_column_index
("
$1
",
$
2
,'');
next
;
}
## TYPES & DEFAULT VALUES ##
my
$col_name
=
'';
my
$col_type
=
'';
my
$col_def
=
'';
# All the type is contained in the same line (type followed by parenthesis)
if
(
$doc
=~
/^\W*(\w+)\W+(\w+\s?\(.*\))/
){
$col_name
=
remove_char
(
$
1
)
;
$col_type
=
$
2
;
if
(
$doc
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;
}
# Default value
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
# All the type is contained in the same line (type followed by parenthesis)
if
(
$doc
=~
/^\W*(\w+)\W+(\w+\s?\(.*\))/
){
$col_name
=
$
1
;
$col_type
=
$
2
;
if
(
$doc
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;
}
# Default value
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
# The type is written in several lines
elsif
(
$doc
=~
/^\W*(\w+)\W+(enum|set)(\s?\(.*)/i
){
# The content is split in several lines
$col_name
=
remove_char
(
$
1
);
$col_type
=
"
$2$3<br />
";
my
$end_type
=
0
;
while
(
$end_type
!=
1
){
my
$line
=
<
SQLFILE
>
;
chomp
$line
;
#Regex counting VOODOO again
$parenth_count
+=
()
=
$line
=~
/\(/gi
;
$parenth_count
-=
()
=
$line
=~
/\)/gi
;
# The type is written in several lines
elsif
(
$doc
=~
/^\W*(\w+)\W+(enum|set)(\s?\(.*)/i
){
# The content is split in several lines
$col_name
=
$
1
;
$col_type
=
"
$2$3<br />
";
my
$end_type
=
0
;
while
(
$end_type
!=
1
){
my
$line
=
<
SQLFILE
>
;
chomp
$line
;
$line
=
remove_char
(
$line
);
# Regex counting VOODOO again
$parenth_count
+=
()
=
$line
=~
/\(/gi
;
$parenth_count
-=
()
=
$line
=~
/\)/gi
;
if
(
$line
=~
/\)/
)
{
# Close parenthesis
$end_type
=
1
;
$line
=~
/^\s*(.+)\)/
;
$col_type
.=
"
$1)
";
}
else
{
# Add the content of the line
$line
=~
/^\s*(.+)/
;
$col_type
.=
$
1
.
'
<br />
';
if
(
$line
=~
/\)/
)
{
# Close parenthesis
$end_type
=
1
;
$line
=~
/^\s*(.+)\)/
;
$col_type
.=
"
$1)
";
}
else
{
# Add the content of the line
$line
=~
/^\s*(.+)/
;
$col_type
.=
$
1
.
'
<br />
';
}
if
(
$line
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;
}
# Default value
}
if
(
$line
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;
}
# Default value
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
# All the type is contained in the same line (type without parenthesis)
elsif
(
$doc
=~
/^\s*\W*(\w+)\W+(\w+)/
){
$col_name
=
remove_char
(
$
1
)
;
$col_type
=
$
2
;
if
(
$doc
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;}
# Default value
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
# All the type is contained in the same line (type without parenthesis)
elsif
(
$doc
=~
/^\s*\W*(\w+)\W+(\w+)/
){
$col_name
=
$
1
;
$col_type
=
$
2
;
if
(
$doc
=~
/default\s*([^,\s]+)\s*.*(,|#).*/i
)
{
$col_def
=
$
1
;}
# Default value
add_column_type_and_default_value
(
$col_name
,
$col_type
,
$col_def
);
}
}
}
}
...
...
@@ -691,7 +680,6 @@ sub add_columns {
my
$table_to_link
=
qq{<a href="#$link">$link</a>}
;
$desc
=~
s/\@link\s?\w+/$table_to_link/
;
#$col =~ /^\s*(\w+)[\s\t]+(.+)\t+(.+)\t(.*)/;
$html
.=
qq{ <tr class="bg$bg"><td><b>$name</b></td><td>$type</td><td>$default</td><td>$desc</td><td>$index</td></tr>\n}
;
if
(
$bg
==
1
)
{
$bg
=
2
;
}
else
{
$bg
=
1
;
}
...
...
@@ -723,7 +711,6 @@ sub add_column_index {
my
$idx_name
=
shift
;
my
$index
=
$idx_type
;
$idx_name
=
remove_char
(
$idx_name
);
if
(
defined
(
$idx_name
))
{
$index
.=
"
:
$idx_name
";
}
...
...
@@ -733,7 +720,6 @@ sub add_column_index {
my
%is_found
=
();
foreach
my
$i_col
(
@idx_cols
)
{
$i_col
=~
s/\s//g
;
# Remove white spaces
$i_col
=
remove_char
(
$i_col
);
# Remove the ` character
# In case of index using a number characters for a column
if
(
$i_col
=~
/(.+)\(\d+\)/
)
{
$i_col
=
$
1
;
...
...
@@ -805,6 +791,7 @@ sub add_legend {
}
# Removed the character(s) ` from the read line.
sub
remove_char
{
my
$text
=
shift
;
$text
=~
s/`//g
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment