MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / parseSQLFile

Function parseSQLFile

tools/sql2graph.php:97–160  ·  view source on GitHub ↗
($filename, &$tables, &$edges)

Source from the content-addressed store, hash-verified

95}
96
97function parseSQLFile($filename, &$tables, &$edges) {
98 //init
99 $tables = array();
100 $edges = array();
101
102 //parse file
103 $file = file($filename);
104 for($i = 0;$i < count($file);++$i)
105 {
106 $line = trim($file[$i]);
107 //node
108 if(beginsWith($line, "CREATE TABLE"))
109 {
110 $parts = explode(" ", $line);
111 $current_table = $parts[2];
112 $tables[$current_table] = array();
113 $j = $i+1;
114 $line = trim($file[$j]);
115 //table
116 while(!beginsWith($line, "CREATE TABLE") && !beginsWith($line, "ALTER TABLE") && $line != "")
117 {
118 //primary key
119 if(beginsWith($line, "PRIMARY KEY"))
120 {
121 $parts = explode(" ", $line);
122 $tables[$current_table][rp($parts[3])][] = "P";
123 }
124 // index
125 elseif(beginsWith($line, "KEY"))
126 {
127 $parts = explode(" ", $line);
128 $tables[$current_table][rp($parts[2])][] = "I";
129 }
130 // normal field
131 else
132 {
133 $parts = explode(" ", $line);
134 if($parts[0] != ")")
135 $tables[$current_table][$parts[0]] = array();
136 }
137 ++$j;
138 $line = trim($file[$j]);
139 }
140 }
141 //edges
142 elseif(beginsWith($line, "ALTER TABLE"))
143 {
144 $parts = explode("`", $line);
145 $from = $parts[1];
146 $j = $i+1;
147 while(beginsWith(trim($file[$j]), "ADD CONSTRAINT"))
148 {
149 $parts = explode(" ", $file[$j]);
150 $to = $parts[9];
151 $tables[$from][rp($parts[7])][] = "F";
152 $edges[] = array(
153 $from,
154 $to,

Callers 1

sql2graph.phpFile · 0.85

Calls 3

countFunction · 0.85
beginsWithFunction · 0.85
rpFunction · 0.85

Tested by

no test coverage detected