(col *DdlColumn)
| 1731 | } |
| 1732 | |
| 1733 | func (m *Sqlbridge) parseDdlConstraint(col *DdlColumn) error { |
| 1734 | |
| 1735 | /* |
| 1736 | http://dev.mysql.com/doc/refman/5.7/en/create-table.html |
| 1737 | |
| 1738 | create_definition: |
| 1739 | col_name column_definition |
| 1740 | | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...) |
| 1741 | [index_option] ... |
| 1742 | | {INDEX|KEY} [index_name] [index_type] (index_col_name,...) |
| 1743 | [index_option] ... |
| 1744 | | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] |
| 1745 | [index_name] [index_type] (index_col_name,...) |
| 1746 | [index_option] ... |
| 1747 | | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...) |
| 1748 | [index_option] ... |
| 1749 | | [CONSTRAINT [symbol]] FOREIGN KEY |
| 1750 | [index_name] (index_col_name,...) reference_definition |
| 1751 | | CHECK (expr) |
| 1752 | |
| 1753 | |
| 1754 | index_type: |
| 1755 | USING {BTREE | HASH} |
| 1756 | reference_definition: |
| 1757 | REFERENCES tbl_name (index_col_name,...) |
| 1758 | [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] |
| 1759 | [ON DELETE reference_option] |
| 1760 | [ON UPDATE reference_option] |
| 1761 | |
| 1762 | CONSTRAINT emails_fk FOREIGN KEY (Email) REFERENCES Emails (Email) COMMENT "hello constraint" |
| 1763 | */ |
| 1764 | |
| 1765 | if m.Cur().T != lex.TokenIdentity { |
| 1766 | return m.ErrMsg("expected 'CONSTRAINT <identity>'") |
| 1767 | } |
| 1768 | col.Name = m.Next().V |
| 1769 | |
| 1770 | switch m.Cur().T { |
| 1771 | case lex.TokenTypeDef, lex.TokenTypeBool, lex.TokenTypeTime, |
| 1772 | lex.TokenTypeText, lex.TokenTypeJson: |
| 1773 | |
| 1774 | col.DataType = m.Next().V |
| 1775 | case lex.TokenTypeFloat, lex.TokenTypeInteger, lex.TokenTypeString, |
| 1776 | lex.TokenTypeVarChar, lex.TokenTypeChar, lex.TokenTypeBigInt: |
| 1777 | col.DataType = m.Next().V |
| 1778 | if m.Cur().T == lex.TokenLeftParenthesis { |
| 1779 | m.Next() |
| 1780 | if m.Cur().T != lex.TokenInteger { |
| 1781 | return m.ErrMsg("expected 'type(integer)'") |
| 1782 | } |
| 1783 | iv, err := strconv.ParseInt(m.Next().V, 10, 64) |
| 1784 | if err != nil { |
| 1785 | return m.ErrMsg("Expected integer") |
| 1786 | } |
| 1787 | col.DataTypeSize = int(iv) |
| 1788 | if m.Next().T != lex.TokenRightParenthesis { |
| 1789 | m.Backup() |
| 1790 | return m.ErrMsg("expected 'type(integer)'") |
no test coverage detected