MCPcopy Create free account
hub / github.com/araddon/qlbridge / parseDdlColumn

Method parseDdlColumn

rel/parse_sql.go:1864–1963  ·  view source on GitHub ↗
(col *DdlColumn)

Source from the content-addressed store, hash-verified

1862}
1863
1864func (m *Sqlbridge) parseDdlColumn(col *DdlColumn) error {
1865
1866 /*
1867 http://dev.mysql.com/doc/refman/5.7/en/create-table.html
1868
1869 create_definition:
1870 col_name column_definition
1871
1872 column_definition:
1873 data_type [NOT NULL | NULL] [DEFAULT default_value]
1874 [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
1875 [COMMENT 'string']
1876 [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
1877 [STORAGE {DISK|MEMORY|DEFAULT}]
1878 [reference_definition]
1879 | data_type [GENERATED ALWAYS] AS (expression)
1880 [VIRTUAL | STORED] [UNIQUE [KEY]] [COMMENT comment]
1881 [NOT NULL | NULL] [[PRIMARY] KEY]
1882
1883 ID int(11) NOT NULL AUTO_INCREMENT,
1884 Email char(150) NOT NULL DEFAULT '',
1885 */
1886
1887 //u.Debugf("create col after colstart?: %v ", m.Cur())
1888
1889 switch m.Cur().T {
1890 case lex.TokenTypeDef, lex.TokenTypeBool, lex.TokenTypeTime,
1891 lex.TokenTypeText, lex.TokenTypeJson:
1892
1893 col.DataType = m.Next().V
1894 case lex.TokenTypeFloat, lex.TokenTypeInteger, lex.TokenTypeString,
1895 lex.TokenTypeVarChar, lex.TokenTypeChar, lex.TokenTypeBigInt:
1896 col.DataType = m.Next().V
1897 if m.Cur().T == lex.TokenLeftParenthesis {
1898 m.Next()
1899 if m.Cur().T != lex.TokenInteger {
1900 return m.ErrMsg("expected 'type(integer)'")
1901 }
1902 iv, err := strconv.ParseInt(m.Next().V, 10, 64)
1903 if err != nil {
1904 return m.ErrMsg("Expected integer")
1905 }
1906 col.DataTypeSize = int(iv)
1907 if m.Next().T != lex.TokenRightParenthesis {
1908 m.Backup()
1909 return m.ErrMsg("expected 'type(integer)'")
1910 }
1911 }
1912 default:
1913 col.Null = true
1914 }
1915
1916 // [NOT NULL | NULL]
1917 switch m.Cur().T {
1918 case lex.TokenNegate:
1919 m.Next()
1920 if m.Cur().T == lex.TokenNull {
1921 col.Null = false

Callers 1

parseCreateColsMethod · 0.95

Calls 5

NewStringNodeFunction · 0.92
CurMethod · 0.65
NextMethod · 0.65
ErrMsgMethod · 0.65
BackupMethod · 0.65

Tested by

no test coverage detected