1 module mysql.protocol;
2 
3 
4 enum CapabilityFlags : uint {
5 	CLIENT_LONG_PASSWORD                = 0x00000001,  // Use the improved version of Old Password Authentication
6 	CLIENT_FOUND_ROWS                   = 0x00000002,  // Send found rows instead of affected rows in EOF_Packet
7 	CLIENT_LONG_FLAG                    = 0x00000004,  // Longer flags in Protocol::ColumnDefinition320
8 	CLIENT_CONNECT_WITH_DB              = 0x00000008,  // One can specify db on connect in Handshake Response Packet
9 	CLIENT_NO_SCHEMA                    = 0x00000010,  // Don't allow database.table.column
10 	CLIENT_COMPRESS                     = 0x00000020,  // Compression protocol supported
11 	CLIENT_ODBC                         = 0x00000040,  // Special handling of ODBC behaviour
12 	CLIENT_LOCAL_FILES                  = 0x00000080,  // Can use LOAD DATA LOCAL
13 	CLIENT_IGNORE_SPACE                 = 0x00000100,  // Parser can ignore spaces before '('
14 	CLIENT_PROTOCOL_41                  = 0x00000200,  // Supports the 4.1 protocol
15 	CLIENT_INTERACTIVE                  = 0x00000400,  // wait_timeout vs. wait_interactive_timeout
16 	CLIENT_SSL                          = 0x00000800,  // Supports SSL
17 	CLIENT_IGNORE_SIGPIPE               = 0x00001000,  // Don't issue SIGPIPE if network failures (libmysqlclient only)
18 	CLIENT_TRANSACTIONS                 = 0x00002000,  // Can send status flags in EOF_Packet
19 	CLIENT_RESERVED                     = 0x00004000,  // Unused
20 	CLIENT_SECURE_CONNECTION            = 0x00008000,  // Supports Authentication::Native41
21 	CLIENT_MULTI_STATEMENTS             = 0x00010000,  // Can handle multiple statements per COM_QUERY and COM_STMT_PREPARE
22 	CLIENT_MULTI_RESULTS                = 0x00020000,  // Can send multiple resultsets for COM_QUERY
23 	CLIENT_PS_MULTI_RESULTS             = 0x00040000,  // Can send multiple resultsets for COM_STMT_EXECUTE
24 	CLIENT_PLUGIN_AUTH                  = 0x00080000,  // Sends extra data in Initial Handshake Packet and supports the pluggable authentication protocol.
25 	CLIENT_CONNECT_ATTRS                = 0x00100000,  // Allows connection attributes in Protocol::HandshakeResponse41
26 	CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = 0x00200000,  // Understands length encoded integer for auth response data in Protocol::HandshakeResponse41
27 	CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 0x00400000,  // Announces support for expired password extension
28 	CLIENT_SESSION_TRACK                = 0x00800000,  // Can set SERVER_SESSION_STATE_CHANGED in the Status Flags and send session-state change data after a OK packet
29 	CLIENT_DEPRECATE_EOF                = 0x01000000,  // Can send OK after a Text Resultset
30 }
31 
32 
33 enum StatusFlags : ushort {
34 	SERVER_STATUS_IN_TRANS	            = 0x0001,  // A transaction is active
35 	SERVER_STATUS_AUTOCOMMIT	        = 0x0002,  // auto-commit is enabled
36 	SERVER_MORE_RESULTS_EXISTS	        = 0x0008,
37 	SERVER_STATUS_NO_GOOD_INDEX_USED    = 0x0010,
38 	SERVER_STATUS_NO_INDEX_USED	        = 0x0020,
39 	SERVER_STATUS_CURSOR_EXISTS	        = 0x0040,  // Used by Binary Protocol Resultset to signal that COM_STMT_FETCH has to be used to fetch the row-data.
40 	SERVER_STATUS_LAST_ROW_SENT	        = 0x0080,
41 	SERVER_STATUS_DB_DROPPED	        = 0x0100,
42 	SERVER_STATUS_NO_BACKSLASH_ESCAPES	= 0x0200,
43 	SERVER_STATUS_METADATA_CHANGED	    = 0x0400,
44 	SERVER_QUERY_WAS_SLOW	            = 0x0800,
45 	SERVER_PS_OUT_PARAMS	            = 0x1000,
46 	SERVER_STATUS_IN_TRANS_READONLY	    = 0x2000,  // In a read-only transaction
47 	SERVER_SESSION_STATE_CHANGED	    = 0x4000,  // connection state information has changed
48 }
49 
50 
51 enum StatusPackets : ubyte {
52 	OK_Packet   = 0,
53 	ERR_Packet  = 0xff,
54 	EOF_Packet  = 0xfe,
55 }
56 
57 
58 enum Commands : ubyte {
59 	//COM_SLEEP           = 0x00,
60 	COM_QUIT            = 0x01,
61 	COM_INIT_DB         = 0x02,
62 	COM_QUERY           = 0x03,
63 	COM_FIELD_LIST      = 0x04,
64 	COM_CREATE_DB       = 0x05,
65 	COM_DROP_DB         = 0x06,
66 	COM_REFRESH         = 0x07,
67 	//COM_SHUTDOWN        = 0x08,
68 	COM_STATISTICS      = 0x09,
69 	COM_PROCESS_INFO    = 0x0a,
70 	//COM_CONNECT         = 0x0b,
71 	COM_PROCESS_KILL    = 0x0c,
72 	COM_DEBUG           = 0x0d,
73 	COM_PING            = 0x0e,
74 	//COM_TIME            = 0x0f,
75 	//COM_DELAYED_INSERT  = 0x10,
76 	COM_CHANGE_USER     = 0x11,
77 	COM_BINLOG_DUMP     = 0x12,
78 	COM_TABLE_DUMP      = 0x13,
79 	//COM_CONNECT_OUT     = 0x14,
80 	COM_REGISTER_SLAVE  = 0x15,
81 	COM_STMT_PREPARE    = 0x16,
82 	COM_STMT_EXECUTE    = 0x17,
83 	COM_STMT_SEND_LONG_DATA = 0x18,
84 	COM_STMT_CLOSE      = 0x19,
85 	COM_STMT_RESET      = 0x1a,
86 	COM_SET_OPTION      = 0x1b,
87 	COM_STMT_FETCH      = 0x1c,
88 	//COM_DAEMON          = 0x1d,
89 	COM_BINLOG_DUMP_GTID = 0x1e,
90 	COM_RESET_CONNECTION = 0x1f,
91 }
92 
93 
94 enum Cursors : ubyte {
95 	CURSOR_TYPE_NO_CURSOR   = 0x00,
96 	CURSOR_TYPE_READ_ONLY   = 0x01,
97 	CURSOR_TYPE_FOR_UPDATE  = 0x02,
98 	CURSOR_TYPE_SCROLLABLE  = 0x04,
99 }
100 
101 
102 enum ColumnTypes : ubyte {
103 	MYSQL_TYPE_DECIMAL      = 0x00,
104 	MYSQL_TYPE_TINY         = 0x01,
105 	MYSQL_TYPE_SHORT        = 0x02,
106 	MYSQL_TYPE_LONG	        = 0x03,
107 	MYSQL_TYPE_FLOAT	    = 0x04,
108 	MYSQL_TYPE_DOUBLE	    = 0x05,
109 	MYSQL_TYPE_NULL	        = 0x06,
110 	MYSQL_TYPE_TIMESTAMP	= 0x07,
111 	MYSQL_TYPE_LONGLONG	    = 0x08,
112 	MYSQL_TYPE_INT24	    = 0x09,
113 	MYSQL_TYPE_DATE	        = 0x0a,
114 	MYSQL_TYPE_TIME	        = 0x0b,
115 	MYSQL_TYPE_DATETIME	    = 0x0c,
116 	MYSQL_TYPE_YEAR	        = 0x0d,
117 	MYSQL_TYPE_NEWDATE  	= 0x0e,
118 	MYSQL_TYPE_VARCHAR	    = 0x0f,
119 	MYSQL_TYPE_BIT	        = 0x10,
120 	MYSQL_TYPE_TIMESTAMP2   = 0x11,
121 	MYSQL_TYPE_DATETIME2    = 0x12,
122 	MYSQL_TYPE_TIME2        = 0x13,
123 	MYSQL_TYPE_JSON         = 0xf5,
124 	MYSQL_TYPE_NEWDECIMAL   = 0xf6,
125 	MYSQL_TYPE_ENUM         = 0xf7,
126 	MYSQL_TYPE_SET	        = 0xf8,
127 	MYSQL_TYPE_TINY_BLOB	= 0xf9,
128 	MYSQL_TYPE_MEDIUM_BLOB	= 0xfa,
129 	MYSQL_TYPE_LONG_BLOB	= 0xfb,
130 	MYSQL_TYPE_BLOB	        = 0xfc,
131 	MYSQL_TYPE_VAR_STRING	= 0xfd,
132 	MYSQL_TYPE_STRING	    = 0xfe,
133 	MYSQL_TYPE_GEOMETRY	    = 0xff,
134 }
135 
136 
137 auto columnTypeName(ColumnTypes type) {
138 	final switch (type) with (ColumnTypes) {
139 	case MYSQL_TYPE_DECIMAL:	return "decimal";
140 	case MYSQL_TYPE_TINY:		return "tiny";
141 	case MYSQL_TYPE_SHORT:		return "short";
142 	case MYSQL_TYPE_LONG:		return "long";
143 	case MYSQL_TYPE_FLOAT:		return "float";
144 	case MYSQL_TYPE_DOUBLE:		return "double";
145 	case MYSQL_TYPE_NULL:		return "null";
146 	case MYSQL_TYPE_TIMESTAMP:	return "timestamp";
147 	case MYSQL_TYPE_LONGLONG:	return "longlong";
148 	case MYSQL_TYPE_INT24:		return "int24";
149 	case MYSQL_TYPE_DATE:		return "date";
150 	case MYSQL_TYPE_TIME:		return "time";
151 	case MYSQL_TYPE_DATETIME:	return "datetime";
152 	case MYSQL_TYPE_YEAR:		return "year";
153 	case MYSQL_TYPE_NEWDATE:	return "newdate";
154 	case MYSQL_TYPE_VARCHAR:	return "varchar";
155 	case MYSQL_TYPE_BIT:		return "bit";
156 	case MYSQL_TYPE_TIMESTAMP2:	return "timestamp2";
157 	case MYSQL_TYPE_DATETIME2:	return "datetime2";
158 	case MYSQL_TYPE_TIME2:		return "time2";
159 	case MYSQL_TYPE_JSON:		return "json";
160 	case MYSQL_TYPE_NEWDECIMAL:	return "newdecimal";
161 	case MYSQL_TYPE_ENUM:		return "enum";
162 	case MYSQL_TYPE_SET:		return "set";
163 	case MYSQL_TYPE_TINY_BLOB:	return "tiny_blob";
164 	case MYSQL_TYPE_MEDIUM_BLOB:return "medium_blob";
165 	case MYSQL_TYPE_LONG_BLOB:	return "long_blob";
166 	case MYSQL_TYPE_BLOB:		return "blob";
167 	case MYSQL_TYPE_VAR_STRING:	return "var_string";
168 	case MYSQL_TYPE_STRING:		return "string";
169 	case MYSQL_TYPE_GEOMETRY:	return "geometry";
170 	}
171 }
172 
173 
174 enum FieldFlags : ushort {
175 	NOT_NULL_FLAG           = 0x0001, //  Field cannot be NULL
176 	PRI_KEY_FLAG	        = 0x0002, //  Field is part of a primary key
177 	UNIQUE_KEY_FLAG	        = 0x0004, //  Field is part of a unique key
178 	MULTIPLE_KEY_FLAG       = 0x0008, //  Field is part of a nonunique key
179 	BLOB_FLAG	            = 0x0010, //  Field is a BLOB or TEXT (deprecated)
180 	UNSIGNED_FLAG	        = 0x0020, //  Field has the UNSIGNED attribute
181 	ZEROFILL_FLAG	        = 0x0040, //  Field has the ZEROFILL attribute
182 	BINARY_FLAG	            = 0x0080, //  Field has the BINARY attribute
183 	ENUM_FLAG	            = 0x0100, //  Field is an ENUM
184 	AUTO_INCREMENT_FLAG	    = 0x0200, //  Field has the AUTO_INCREMENT attribute
185 	TIMESTAMP_FLAG	        = 0x0400, //  Field is a TIMESTAMP (deprecated)
186 	SET_FLAG	            = 0x0800, //  Field is a SET
187 	NO_DEFAULT_VALUE_FLAG   = 0x1000, //  Field has no default value; see additional notes following table
188 	ON_UPDATE_NOW_FLAG      = 0x2000, // Field is set to NOW on UPDATE
189 //    PART_KEY_FLAG           = 0x4000, //  Intern; Part of some key
190 	NUM_FLAG	            = 0x8000, //  Field is numeric
191 }
192 
193 
194 enum ErrorCodes : ushort {
195 	ER_DUP_KEYNAME                  = 1061,
196 	ER_DUP_ENTRY                    = 1062,
197 	ER_DUP_ENTRY_WITH_KEY_NAME      = 1586,
198 }