1 module hunt.database.driver.mysql.impl.codec.ColumnDefinition;
2 
3 import hunt.database.driver.mysql.impl.codec.DataType;
4 import hunt.database.driver.mysql.impl.codec.DataTypeDesc;
5 import std.conv;
6 
7 /**
8  * 
9  * 
10  * See_Also:
11  *      https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_query_response_text_resultset_column_definition.html
12  */
13 final class ColumnDefinition {
14     private string _catalog;
15     private string _schema;
16     private string _table;
17     private string _orgTable;
18     private string _name;
19     private string _orgName;
20     private int _characterSet;
21     private long _columnLength;
22     private DataType _type;
23     private int _flags;
24     private byte _decimals;
25 
26     this(string catalog,
27         string schema,
28         string table,
29         string orgTable,
30         string name,
31         string orgName,
32         int characterSet,
33         long columnLength,
34         DataType type,
35         int flags,
36         byte decimals) {
37         this._catalog = catalog;
38         this._schema = schema;
39         this._table = table;
40         this._orgTable = orgTable;
41         this._name = name;
42         this._orgName = orgName;
43         this._characterSet = characterSet;
44         this._columnLength = columnLength;
45         this._type = type;
46         this._flags = flags;
47         this._decimals = decimals;
48     }
49 
50     string catalog() {
51         return _catalog;
52     }
53 
54     string schema() {
55         return _schema;
56     }
57 
58     string table() {
59         return _table;
60     }
61 
62     string orgTable() {
63         return _orgTable;
64     }
65 
66     string name() {
67         return _name;
68     }
69 
70     string orgName() {
71         return _orgName;
72     }
73 
74     int characterSet() {
75         return _characterSet;
76     }
77 
78     long columnLength() {
79         return _columnLength;
80     }
81 
82     DataType type() {
83         return _type;
84     }
85 
86     int flags() {
87         return _flags;
88     }
89 
90     byte decimals() {
91         return _decimals;
92     }
93 
94     override
95     string toString() {
96         return "ColumnDefinition{" ~
97             "catalog='" ~ _catalog ~ "\'" ~
98             ", schema='" ~ _schema ~ "\'" ~
99             ", table='" ~ _table ~ "\'" ~
100             ", orgTable='" ~ _orgTable ~ "\'" ~
101             ", name='" ~ _name ~ "\'" ~
102             ", orgName='" ~ _orgName ~ "\'" ~
103             ", characterSet=" ~ _characterSet.to!string() ~
104             ", columnLength=" ~ _columnLength.to!string() ~
105             ", type=" ~ _type.to!string() ~
106             ", flags=" ~ _flags.to!string() ~
107             ", decimals=" ~ _decimals.to!string() ~
108             '}';
109     }
110 
111 }
112 
113 
114 /*
115     https://dev.mysql.com/doc/dev/mysql-server/latest/group__group__cs__column__definition__flags.html
116  */
117 enum ColumnDefinitionFlags : int {
118     NOT_NULL_FLAG = 0x00000001,
119     PRI_KEY_FLAG = 0x00000002,
120     UNIQUE_KEY_FLAG = 0x00000004,
121     MULTIPLE_KEY_FLAG = 0x00000008,
122     BLOB_FLAG = 0x00000010,
123     UNSIGNED_FLAG = 0x00000020,
124     ZEROFILL_FLAG = 0x00000040,
125     BINARY_FLAG = 0x00000080,
126     ENUM_FLAG = 0x00000100,
127     AUTO_INCREMENT_FLAG = 0x00000200,
128     TIMESTAMP_FLAG = 0x00000400,
129     SET_FLAG = 0x00000800,
130     NO_DEFAULT_VALUE_FLAG = 0x00001000,
131     ON_UPDATE_NOW_FLAG = 0x00002000,
132     NUM_FLAG = 0x00008000,
133     PART_KEY_FLAG = 0x00004000,
134     GROUP_FLAG = 0x00008000,
135     UNIQUE_FLAG = 0x00010000,
136     BINCMP_FLAG = 0x00020000,
137     GET_FIXED_FIELDS_FLAG = 0x00040000,
138     FIELD_IN_PART_FUNC_FLAG = 0x00080000,
139     FIELD_IN_ADD_INDEX = 0x00100000,
140     FIELD_IS_RENAMED = 0x00200000,
141     FIELD_FLAGS_STORAGE_MEDIA = 22,
142     FIELD_FLAGS_STORAGE_MEDIA_MASK = 3 << FIELD_FLAGS_STORAGE_MEDIA,
143     FIELD_FLAGS_COLUMN_FORMAT = 24,
144     FIELD_FLAGS_COLUMN_FORMAT_MASK = 3 << FIELD_FLAGS_COLUMN_FORMAT,
145     FIELD_IS_DROPPED = 0x04000000,
146     EXPLICIT_NULL_FLAG = 0x08000000,
147     FIELD_IS_MARKED = 0x10000000
148 }