diff options
author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-11-28 12:19:11 +0000 |
---|---|---|
committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-11-28 12:19:11 +0000 |
commit | 86b0303fd6d078f3d07528666d491a240b09d8af (patch) | |
tree | 3395761a0b1edbf865a2f57b7f8b25f78a4c8717 /create/schema/gen.pl | |
parent | b5fb0670a9b9816765320514bfe2139dbfe079b5 (diff) | |
download | zabbix-86b0303fd6d078f3d07528666d491a240b09d8af.tar.gz zabbix-86b0303fd6d078f3d07528666d491a240b09d8af.tar.xz zabbix-86b0303fd6d078f3d07528666d491a240b09d8af.zip |
Better gen.pl.
git-svn-id: svn://svn.zabbix.com/trunk@3536 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'create/schema/gen.pl')
-rwxr-xr-x | create/schema/gen.pl | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/create/schema/gen.pl b/create/schema/gen.pl index 89626f9e..1526a23a 100755 --- a/create/schema/gen.pl +++ b/create/schema/gen.pl @@ -24,6 +24,8 @@ open(INFO, $file); # Open the file @lines = <INFO>; # Read it into an array close(INFO); # Close the file +local $output; + %mysql=("t_bigint" => "bigint unsigned", "t_id" => "bigint unsigned", "t_integer" => "integer", @@ -51,17 +53,17 @@ close(INFO); # Close the file "t_blob" => "blob" ); -%postgresql=("t_bigint" => "bigint", - "t_id" => "bigint", +%postgresql=("t_bigint" => "unsigned bigint", + "t_id" => "unsigned bigint", "t_integer" => "integer", "t_serial" => "serial", - "t_double" => "double", + "t_double" => "float8", "t_varchar" => "varchar", "t_char" => "char", - "t_image" => "longblob", - "t_history_log" => "text", + "t_image" => "bytea", + "t_history_log" => "varchar(255)", "t_history_text"=> "text", - "t_blob" => "blob" + "t_blob" => "text" ); %sqlite=("t_bigint" => "bigint", @@ -77,6 +79,12 @@ close(INFO); # Close the file "t_blob" => "blob" ); +%all=( "mysql" => %mysql, + "oracle" => %oracle, + "postgresql" => %postgresql, + "sqlite" => %sqlite, +); + sub newstate { local $new=$_[0]; @@ -114,7 +122,7 @@ sub process_field newstate("field"); ($name,$type,$default,$null,$flags)=split(/\|/, $line,5); ($type_short)=split(/\(/, $type,2); - $a=$mysql{$type_short}; + $a=$output{$type_short}; $_=$type; s/$type_short/$a/g; $type_2=$_; @@ -139,22 +147,48 @@ sub process_index } } -foreach $line (@lines) +sub usage { - $_ = $line; - $line = tr/\t//d; - $line=$_; - - chop($line); + printf "Usage: gen.pl [mysql|oracle|postgresql|sqlite]\n"; + printf "The script generates ZABBIX SQL schemas for different database engines.\n"; + exit; +} - ($type,$line)=split(/\|/, $line,2); +sub main +{ + if($#ARGV!=0) + { + usage(); + }; + + $format=$ARGV[0]; + switch ($format) { + case "mysql" { $output=%mysql; } + case "oracle" { $output=%oracle; } + case "postgresql" { $output=%postgresql; } + case "sqlite" { $output=%sqlite; } + else { usage(); } + } - switch ($type) { - case "TABLE" { process_table($line); } - case "INDEX" { process_index($line,0); } - case "UNIQUE" { process_index($line,1); } - case "FIELD" { process_field($line); } + foreach $line (@lines) + { + $_ = $line; + $line = tr/\t//d; + $line=$_; + + chop($line); + + ($type,$line)=split(/\|/, $line,2); + + switch ($type) { + case "TABLE" { process_table($line); } + case "INDEX" { process_index($line,0); } + case "UNIQUE" { process_index($line,1); } + case "FIELD" { process_field($line); } + } } } +main(); + newstate("table"); |