Skip to content

Commit b08b393

Browse files
authored
Merge pull request #439 from dolthub/elian/9887
dolthub/dolt#9887: Fix empty executable comments and add `BINLOG` support and `mariadb` executable comments
2 parents 8b6ef7b + 682aa29 commit b08b393

File tree

13 files changed

+14225
-13998
lines changed

13 files changed

+14225
-13998
lines changed

go/mysql/binlog_event.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ type BinlogEvent interface {
127127

128128
// Bytes returns the binary representation of the event
129129
Bytes() []byte
130+
131+
// TypeName returns a human-readable name for the event type.
132+
TypeName() string
130133
}
131134

132135
// BinlogFormat contains relevant data from the FORMAT_DESCRIPTION_EVENT.

go/mysql/binlog_event_common.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package mysql
1919
import (
2020
"bytes"
2121
"encoding/binary"
22+
"fmt"
2223

2324
binlogdatapb "github.com/dolthub/vitess/go/vt/proto/binlogdata"
2425
"github.com/dolthub/vitess/go/vt/proto/vtrpc"
@@ -81,6 +82,40 @@ func (ev binlogEvent) Type() byte {
8182
return ev.Bytes()[4]
8283
}
8384

85+
// TypeName returns a human-readable name for the event type.
86+
// This matches MariaDB's Log_event::get_type_str() function for consistency.
87+
func (ev binlogEvent) TypeName() string {
88+
eventType := ev.Type()
89+
switch eventType {
90+
case eQueryEvent:
91+
return "Query"
92+
case eRotateEvent:
93+
return "Rotate"
94+
case eFormatDescriptionEvent:
95+
return "Format_desc"
96+
case eXIDEvent:
97+
return "Xid"
98+
case eTableMapEvent:
99+
return "Table_map"
100+
case eWriteRowsEventV1:
101+
return "Write_rows_v1"
102+
case eUpdateRowsEventV1:
103+
return "Update_rows_v1"
104+
case eDeleteRowsEventV1:
105+
return "Delete_rows_v1"
106+
case eWriteRowsEventV2:
107+
return "Write_rows"
108+
case eUpdateRowsEventV2:
109+
return "Update_rows"
110+
case eDeleteRowsEventV2:
111+
return "Delete_rows"
112+
case eMariaGTIDEvent:
113+
return "Gtid"
114+
default:
115+
return fmt.Sprintf("Unknown (type %d)", eventType)
116+
}
117+
}
118+
84119
// Flags returns the flags field from the header.
85120
func (ev binlogEvent) Flags() uint16 {
86121
return binary.LittleEndian.Uint16(ev.Bytes()[17 : 17+2])

go/mysql/binlog_event_filepos.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func (ev filePosQueryEvent) StripChecksum(f BinlogFormat) (BinlogEvent, []byte,
114114
return ev, nil, nil
115115
}
116116

117+
func (ev filePosQueryEvent) TypeName() string {
118+
return "Query"
119+
}
120+
117121
//----------------------------------------------------------------------------
118122

119123
// filePosFakeEvent is the base class for fake events.
@@ -253,6 +257,10 @@ func (ev filePosGTIDEvent) StripChecksum(f BinlogFormat) (BinlogEvent, []byte, e
253257
return ev, nil, nil
254258
}
255259

260+
func (ev filePosGTIDEvent) TypeName() string {
261+
return "Gtid"
262+
}
263+
256264
func (ev filePosGTIDEvent) GTID(BinlogFormat) (GTID, bool, error) {
257265
return ev.gtid, false, nil
258266
}

go/mysql/constants.go

Lines changed: 113 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -438,116 +438,119 @@ const (
438438
ERLockDeadlock = 1213
439439

440440
// invalid arg
441-
ERUnknownComError = 1047
442-
ERBadNullError = 1048
443-
ERBadDb = 1049
444-
ERBadTable = 1051
445-
ERNonUniq = 1052
446-
ERWrongFieldWithGroup = 1055
447-
ERWrongGroupField = 1056
448-
ERWrongSumSelect = 1057
449-
ERWrongValueCount = 1058
450-
ERTooLongIdent = 1059
451-
ERDupFieldName = 1060
452-
ERDupKeyName = 1061
453-
ERWrongFieldSpec = 1063
454-
ERParseError = 1064
455-
EREmptyQuery = 1065
456-
ERNonUniqTable = 1066
457-
ERInvalidDefault = 1067
458-
ERMultiplePriKey = 1068
459-
ERTooManyKeys = 1069
460-
ERTooManyKeyParts = 1070
461-
ERTooLongKey = 1071
462-
ERKeyColumnDoesNotExist = 1072
463-
ERBlobUsedAsKey = 1073
464-
ERTooBigFieldLength = 1074
465-
ERWrongAutoKey = 1075
466-
ERWrongFieldTerminators = 1083
467-
ERBlobsAndNoTerminated = 1084
468-
ERTextFileNotReadable = 1085
469-
ERWrongSubKey = 1089
470-
ERCantRemoveAllFields = 1090
471-
ERUpdateTableUsed = 1093
472-
ERNoTablesUsed = 1096
473-
ERTooBigSet = 1097
474-
ERBlobCantHaveDefault = 1101
475-
ERWrongDbName = 1102
476-
ERWrongTableName = 1103
477-
ERUnknownProcedure = 1106
478-
ERWrongParamCountToProcedure = 1107
479-
ERWrongParametersToProcedure = 1108
480-
ERFieldSpecifiedTwice = 1110
481-
ERInvalidGroupFuncUse = 1111
482-
ERTableMustHaveColumns = 1113
483-
ERUnknownCharacterSet = 1115
484-
ERTooManyTables = 1116
485-
ERTooManyFields = 1117
486-
ERTooBigRowSize = 1118
487-
ERWrongOuterJoin = 1120
488-
ERNullColumnInIndex = 1121
489-
ERFunctionNotDefined = 1128
490-
ERWrongValueCountOnRow = 1136
491-
ERInvalidUseOfNull = 1138
492-
ERRegexpError = 1139
493-
ERMixOfGroupFuncAndFields = 1140
494-
ERIllegalGrantForTable = 1144
495-
ERSyntaxError = 1149
496-
ERWrongColumnName = 1166
497-
ERWrongKeyColumn = 1167
498-
ERBlobKeyWithoutLength = 1170
499-
ERPrimaryCantHaveNull = 1171
500-
ERTooManyRows = 1172
501-
ERLockOrActiveTransaction = 1192
502-
ERUnknownSystemVariable = 1193
503-
ERSetConstantsOnly = 1204
504-
ERWrongArguments = 1210
505-
ERWrongUsage = 1221
506-
ERWrongNumberOfColumnsInSelect = 1222
507-
ERDupArgument = 1225
508-
ERLocalVariable = 1228
509-
ERGlobalVariable = 1229
510-
ERWrongValueForVar = 1231
511-
ERWrongTypeForVar = 1232
512-
ERVarCantBeRead = 1233
513-
ERCantUseOptionHere = 1234
514-
ERIncorrectGlobalLocalVar = 1238
515-
ERWrongFKDef = 1239
516-
ERKeyRefDoNotMatchTableRef = 1240
517-
ERCyclicReference = 1245
518-
ERIllegalReference = 1247
519-
ERDerivedMustHaveAlias = 1248
520-
ERTableNameNotAllowedHere = 1250
521-
ERCollationCharsetMismatch = 1253
522-
ERWarnDataTruncated = 1265
523-
ERCantAggregate2Collations = 1267
524-
ERCantAggregate3Collations = 1270
525-
ERCantAggregateNCollations = 1271
526-
ERVariableIsNotStruct = 1272
527-
ERUnknownCollation = 1273
528-
ERWrongNameForIndex = 1280
529-
ERWrongNameForCatalog = 1281
530-
ERBadFTColumn = 1283
531-
ERTruncatedWrongValue = 1292
532-
ERTooMuchAutoTimestampCols = 1293
533-
ERInvalidOnUpdate = 1294
534-
ERUnknownTimeZone = 1298
535-
ERInvalidCharacterString = 1300
536-
ERQueryInterrupted = 1317
537-
ERTruncatedWrongValueForField = 1366
538-
ERIllegalValueForType = 1367
539-
ERDataTooLong = 1406
540-
ErrWrongValueForType = 1411
541-
ERForbidSchemaChange = 1450
542-
ERWrongValue = 1525
543-
ERDataOutOfRange = 1690
544-
ERInvalidJSONText = 3140
545-
ERInvalidJSONTextInParams = 3141
546-
ERInvalidJSONBinaryData = 3142
547-
ERInvalidJSONCharset = 3144
548-
ERInvalidCastToJSON = 3147
549-
ERJSONValueTooBig = 3150
550-
ERJSONDocumentTooDeep = 3157
441+
ERUnknownComError = 1047
442+
ERBadNullError = 1048
443+
ERBadDb = 1049
444+
ERBadTable = 1051
445+
ERNonUniq = 1052
446+
ERWrongFieldWithGroup = 1055
447+
ERWrongGroupField = 1056
448+
ERWrongSumSelect = 1057
449+
ERWrongValueCount = 1058
450+
ERTooLongIdent = 1059
451+
ERDupFieldName = 1060
452+
ERDupKeyName = 1061
453+
ERWrongFieldSpec = 1063
454+
ERParseError = 1064
455+
EREmptyQuery = 1065
456+
ERNonUniqTable = 1066
457+
ERInvalidDefault = 1067
458+
ERMultiplePriKey = 1068
459+
ERTooManyKeys = 1069
460+
ERTooManyKeyParts = 1070
461+
ERTooLongKey = 1071
462+
ERKeyColumnDoesNotExist = 1072
463+
ERBlobUsedAsKey = 1073
464+
ERTooBigFieldLength = 1074
465+
ERWrongAutoKey = 1075
466+
ERWrongFieldTerminators = 1083
467+
ERBlobsAndNoTerminated = 1084
468+
ERTextFileNotReadable = 1085
469+
ERWrongSubKey = 1089
470+
ERCantRemoveAllFields = 1090
471+
ERUpdateTableUsed = 1093
472+
ERNoTablesUsed = 1096
473+
ERTooBigSet = 1097
474+
ERBlobCantHaveDefault = 1101
475+
ERWrongDbName = 1102
476+
ERWrongTableName = 1103
477+
ERUnknownProcedure = 1106
478+
ERWrongParamCountToProcedure = 1107
479+
ERWrongParametersToProcedure = 1108
480+
ERFieldSpecifiedTwice = 1110
481+
ERInvalidGroupFuncUse = 1111
482+
ERTableMustHaveColumns = 1113
483+
ERUnknownCharacterSet = 1115
484+
ERTooManyTables = 1116
485+
ERTooManyFields = 1117
486+
ERTooBigRowSize = 1118
487+
ERWrongOuterJoin = 1120
488+
ERNullColumnInIndex = 1121
489+
ERFunctionNotDefined = 1128
490+
ERWrongValueCountOnRow = 1136
491+
ERInvalidUseOfNull = 1138
492+
ERRegexpError = 1139
493+
ERMixOfGroupFuncAndFields = 1140
494+
ERIllegalGrantForTable = 1144
495+
ERSyntaxError = 1149
496+
ERWrongColumnName = 1166
497+
ERWrongKeyColumn = 1167
498+
ERBlobKeyWithoutLength = 1170
499+
ERPrimaryCantHaveNull = 1171
500+
ERTooManyRows = 1172
501+
ERLockOrActiveTransaction = 1192
502+
ERUnknownSystemVariable = 1193
503+
ERSetConstantsOnly = 1204
504+
ERWrongArguments = 1210
505+
ERWrongUsage = 1221
506+
ERWrongNumberOfColumnsInSelect = 1222
507+
ERDupArgument = 1225
508+
ERLocalVariable = 1228
509+
ERGlobalVariable = 1229
510+
ERWrongValueForVar = 1231
511+
ERWrongTypeForVar = 1232
512+
ERVarCantBeRead = 1233
513+
ERCantUseOptionHere = 1234
514+
ERIncorrectGlobalLocalVar = 1238
515+
ERWrongFKDef = 1239
516+
ERKeyRefDoNotMatchTableRef = 1240
517+
ERCyclicReference = 1245
518+
ERIllegalReference = 1247
519+
ERDerivedMustHaveAlias = 1248
520+
ERTableNameNotAllowedHere = 1250
521+
ERCollationCharsetMismatch = 1253
522+
ERWarnDataTruncated = 1265
523+
ERCantAggregate2Collations = 1267
524+
ERCantAggregate3Collations = 1270
525+
ERCantAggregateNCollations = 1271
526+
ERVariableIsNotStruct = 1272
527+
ERUnknownCollation = 1273
528+
ERWrongNameForIndex = 1280
529+
ERWrongNameForCatalog = 1281
530+
ERBadFTColumn = 1283
531+
ERTruncatedWrongValue = 1292
532+
ERTooMuchAutoTimestampCols = 1293
533+
ERInvalidOnUpdate = 1294
534+
ERUnknownTimeZone = 1298
535+
ERInvalidCharacterString = 1300
536+
ERQueryInterrupted = 1317
537+
ERTruncatedWrongValueForField = 1366
538+
ERIllegalValueForType = 1367
539+
ERDataTooLong = 1406
540+
ErrWrongValueForType = 1411
541+
ERForbidSchemaChange = 1450
542+
ERWrongValue = 1525
543+
ERBase64DecodeError = 1575
544+
ERNoFormatDescriptionEventBeforeBinlogStatement = 1609
545+
ERDataOutOfRange = 1690
546+
EROnlyFDAndRBREventsAllowedInBinlogStatement = 1730
547+
ERInvalidJSONText = 3140
548+
ERInvalidJSONTextInParams = 3141
549+
ERInvalidJSONBinaryData = 3142
550+
ERInvalidJSONCharset = 3144
551+
ERInvalidCastToJSON = 3147
552+
ERJSONValueTooBig = 3150
553+
ERJSONDocumentTooDeep = 3157
551554

552555
// max execution time exceeded
553556
ERQueryTimeout = 3024

go/vt/sqlparser/ast.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ func (*RollbackSavepoint) iStatement() {}
480480
func (*ReleaseSavepoint) iStatement() {}
481481
func (*LockTables) iStatement() {}
482482
func (*UnlockTables) iStatement() {}
483+
func (*Binlog) iStatement() {}
483484

484485
// ParenSelect can actually not be a top level statement,
485486
// but we have to allow it because it's a requirement
@@ -8324,3 +8325,41 @@ func (d InjectedStatement) SetAuthTargetNames(targetNames []string) {
83248325
func (d InjectedStatement) SetExtra(extra any) {
83258326
d.Auth.Extra = extra
83268327
}
8328+
8329+
// Binlog represents a BINLOG statement that executes base64-encoded binary log events.
8330+
type Binlog struct {
8331+
Base64Str string
8332+
Auth AuthInformation
8333+
}
8334+
8335+
var _ AuthNode = (*Binlog)(nil)
8336+
8337+
// Format formats the node.
8338+
func (node *Binlog) Format(buf *TrackedBuffer) {
8339+
buf.Myprintf("binlog '%s'", node.Base64Str)
8340+
}
8341+
8342+
// GetAuthInformation returns the authorization information for this node.
8343+
func (node *Binlog) GetAuthInformation() AuthInformation {
8344+
return node.Auth
8345+
}
8346+
8347+
// SetAuthType sets the authorization type.
8348+
func (node *Binlog) SetAuthType(authType string) {
8349+
node.Auth.AuthType = authType
8350+
}
8351+
8352+
// SetAuthTargetType sets the authorization target type.
8353+
func (node *Binlog) SetAuthTargetType(targetType string) {
8354+
node.Auth.TargetType = targetType
8355+
}
8356+
8357+
// SetAuthTargetNames sets the authorization target names.
8358+
func (node *Binlog) SetAuthTargetNames(targetNames []string) {
8359+
node.Auth.TargetNames = targetNames
8360+
}
8361+
8362+
// SetExtra sets extra authorization information.
8363+
func (node *Binlog) SetExtra(extra any) {
8364+
node.Auth.Extra = extra
8365+
}

go/vt/sqlparser/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
AuthType_ALTER = "ALTER"
5959
AuthType_ALTER_ROUTINE = "ALTER_ROUTINE"
6060
AuthType_ALTER_USER = "ALTER_USER"
61+
AuthType_BINLOG = "BINLOG"
6162
AuthType_CALL = "CALL"
6263
AuthType_CREATE = "CREATE"
6364
AuthType_CREATE_ROLE = "CREATE_ROLE"

0 commit comments

Comments
 (0)