/**
  * Parses all rows in ALTER TABLE command.
  *
  * @param table table being parsed
  * @param commands commands
  *
  * @throws ParserException Thrown if problem occured while parsing DDL.
  */
 private static function parse_rows(&$db_doc, &$node_schema, &$node_table, $commands)
 {
     $line = $commands;
     $subCommand = null;
     while (strlen($line) > 0) {
         $commandEnd = sql_parser::get_command_end($line, 0);
         $subCommand = trim(substr($line, 0, $commandEnd));
         $line = $commandEnd >= strlen($line) ? "" : substr($line, $commandEnd + 1);
         if (strlen($subCommand) > 0) {
             if (preg_match(self::PATTERN_ADD_CONSTRAINT_FOREIGN_KEY, $subCommand, $matches) > 0) {
                 $column_name = trim($matches[3]);
                 $constraint_name = trim($matches[1]);
                 $node_constraint = pgsql8_constraint::get_table_constraint($db_doc, $node_table, $constraint_name, true);
                 dbx::set_attribute($node_constraint, 'definition', trim($matches[2]));
                 $subCommand = "";
             }
         }
         if (preg_match(self::PATTERN_ADD_CONSTRAINT, $subCommand, $matches) > 0) {
             $constraint_name = trim($matches[1]);
             $node_constraint = pgsql8_constraint::get_table_constraint($db_doc, $node_table, $constraint_name, true);
             dbx::set_attribute($node_constraint, 'definition', trim($matches[2]));
             $subCommand = "";
         }
         if (strlen($subCommand) > 0) {
             if (preg_match(self::PATTERN_ADD_PRIMARY_KEY, $subCommand, $matches) > 0) {
                 $definition = trim($matches[1]);
                 $column_name = trim($matches[2]);
                 $constraint_name = $node_table['name'] . '_pkey';
                 dbx::set_attribute($node_table, 'primaryKey', $column_name);
                 $subCommand = "";
             }
         }
         if (strlen($subCommand) > 0) {
             if (preg_match(self::PATTERN_ADD_FOREIGN_KEY, $subCommand, $matches) > 0) {
                 $column_name = trim($matches[2]);
                 $constraint_name = pgsql8::identifier_name($node_schema['name'], $node_table['name'], $column_name, '_fkey');
                 $node_constraint = pgsql8_constraint::get_table_constraint($db_doc, $node_table, $constraint_name, true);
                 dbx::set_attribute($node_constraint, 'definition', trim($matches[1]));
                 $subCommand = "";
             }
         }
         if (strlen($subCommand) > 0) {
             if (preg_match(self::PATTERN_SET_DEFAULT, $subCommand, $matches) > 0) {
                 $column_name = trim($matches[1]);
                 $default_value = trim($matches[2]);
                 if ($node_table->contains_column($column_name)) {
                     $node_column =& dbx::get_column($node_table, $column_name);
                     dbx::set_attribute($node_column, 'default', $default_value);
                 } else {
                     throw new exception("Cannot find column '" . $column_name . " 'in table '" . $node_table['name'] . "'");
                 }
                 $subCommand = "";
             }
         }
         if (preg_match(self::PATTERN_ALTER_COLUMN_STATISTICS, $subCommand, $matches) > 0) {
             $column_name = trim($matches[2]);
             $value = trim($matches[3]);
             $node_column =& dbx::get_column($node_table, $column_name);
             dbx::set_attribute($node_column, 'statistics', $value);
             $subCommand = "";
         }
         if (preg_match(self::PATTERN_CLUSTER_ON, $subCommand, $matches) > 0) {
             $indexName = trim($matches[1]);
             dbx::set_attribute($node_column, 'clusterIndexName', $indexName);
             $subCommand = "";
         }
         if (strlen($subCommand) > 0) {
             if (preg_match(self::PATTERN_TRIGGER, $subCommand, $matches) > 0) {
                 $triggerName = trim($matches[2]);
                 throw new exception("@TODO: do something with ALTER TABLE ... ENABLE / DISABLE trigger statements");
                 $subCommand = "";
             }
         }
         if (strlen($subCommand) > 0) {
             throw new exception("Don't know how to parse: " . $subCommand);
         }
     }
 }