title: How to parse correctly an SQL CREATE TABLE statement
body: <p>I need to parse SQL "CREATE TABLE" statements, to get the field list and their properties.</p>
  
  <p>It is mostly MySQL syntax, which should be (with incontrolable nested brackets like this example :</p>
  
  <pre><code>CREATE TABLE 'tablename' (
  field1 INT,
  field2 VARCHAR(10),
  field3 FLOAT NOT NULL DEFAULT 0,
  PRIMARY KEY (field1, field2),
  (CONSTRAINT fk FOREIGN KEY whatever)
  ) options;
  </code></pre>
  
  <p>I can easily isolate the column definitions but then I'd like to split the definitions. Splitting on commas is not possible as these can be in nested brackets.</p>
  
  <p>I could iterate though the string to count opening and closing string delimiters (quotes etc.), count opening and closing brackets, so I can detect "first level" commas and split on them.</p>
  
  <p>But I wonder if there could not be more effective ways, like for example using regular expressions, but I'm not good enough at them to determine if some regex could match such complex syntax ...</p>