Skip to content

Commit e4016d9

Browse files
committed
add comments
1 parent 447f4ca commit e4016d9

File tree

11 files changed

+575
-12
lines changed

11 files changed

+575
-12
lines changed

src/SciSharp.MySQL.Replication/ColumnType.cs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,169 @@
44

55
namespace SciSharp.MySQL.Replication
66
{
7+
/// <summary>
8+
/// Represents the MySQL column data types as they appear in the binary log format.
9+
/// These values correspond to the type codes used in TABLE_MAP_EVENT to describe table columns.
10+
/// </summary>
11+
/// <remarks>
12+
/// The values match those defined in the MySQL source code in the enum_field_types enumeration,
13+
/// which can be found in mysql-server/include/mysql_com.h.
14+
/// </remarks>
715
public enum ColumnType : byte
816
{
17+
/// <summary>
18+
/// MySQL DECIMAL type (old precision-based format, rarely used).
19+
/// </summary>
920
DECIMAL = 0,
21+
22+
/// <summary>
23+
/// MySQL TINY (TINYINT) type, 1-byte integer.
24+
/// </summary>
1025
TINY = 1,
26+
27+
/// <summary>
28+
/// MySQL SHORT (SMALLINT) type, 2-byte integer.
29+
/// </summary>
1130
SHORT = 2,
31+
32+
/// <summary>
33+
/// MySQL LONG (INT) type, 4-byte integer.
34+
/// </summary>
1235
LONG = 3,
36+
37+
/// <summary>
38+
/// MySQL FLOAT type, 4-byte single-precision floating point.
39+
/// </summary>
1340
FLOAT = 4,
41+
42+
/// <summary>
43+
/// MySQL DOUBLE type, 8-byte double-precision floating point.
44+
/// </summary>
1445
DOUBLE = 5,
46+
47+
/// <summary>
48+
/// MySQL NULL type, represents NULL values.
49+
/// </summary>
1550
NULL = 6,
51+
52+
/// <summary>
53+
/// MySQL TIMESTAMP type, represents a point in time.
54+
/// </summary>
1655
TIMESTAMP = 7,
56+
57+
/// <summary>
58+
/// MySQL LONGLONG (BIGINT) type, 8-byte integer.
59+
/// </summary>
1760
LONGLONG = 8,
61+
62+
/// <summary>
63+
/// MySQL INT24 (MEDIUMINT) type, 3-byte integer.
64+
/// </summary>
1865
INT24 = 9,
66+
67+
/// <summary>
68+
/// MySQL DATE type, represents a calendar date.
69+
/// </summary>
1970
DATE = 10,
71+
72+
/// <summary>
73+
/// MySQL TIME type, represents a time of day.
74+
/// </summary>
2075
TIME = 11,
76+
77+
/// <summary>
78+
/// MySQL DATETIME type, represents a combined date and time.
79+
/// </summary>
2180
DATETIME = 12,
81+
82+
/// <summary>
83+
/// MySQL YEAR type, 1-byte representation of a year.
84+
/// </summary>
2285
YEAR = 13,
86+
87+
/// <summary>
88+
/// MySQL NEWDATE type, new internal representation of DATE (rarely used externally).
89+
/// </summary>
2390
NEWDATE = 14,
91+
92+
/// <summary>
93+
/// MySQL VARCHAR type, variable-length character string.
94+
/// </summary>
2495
VARCHAR = 15,
96+
97+
/// <summary>
98+
/// MySQL BIT type, for storing bit values.
99+
/// </summary>
25100
BIT = 16,
101+
102+
/// <summary>
103+
/// MySQL TIMESTAMP2 type, timestamp with fractional seconds, introduced in MySQL 5.6.4.
104+
/// </summary>
26105
TIMESTAMP_V2 = 17,
106+
107+
/// <summary>
108+
/// MySQL DATETIME2 type, datetime with fractional seconds, introduced in MySQL 5.6.4.
109+
/// </summary>
27110
DATETIME_V2 = 18,
111+
112+
/// <summary>
113+
/// MySQL TIME2 type, time with fractional seconds, introduced in MySQL 5.6.4.
114+
/// </summary>
28115
TIME_V2 = 19,
116+
117+
/// <summary>
118+
/// MySQL JSON type for storing JSON documents, introduced in MySQL 5.7.
119+
/// </summary>
29120
JSON = 245,
121+
122+
/// <summary>
123+
/// MySQL NEWDECIMAL type, new precision-based decimal implementation.
124+
/// </summary>
30125
NEWDECIMAL = 246,
126+
127+
/// <summary>
128+
/// MySQL ENUM type, enumeration of string values.
129+
/// </summary>
31130
ENUM = 247,
131+
132+
/// <summary>
133+
/// MySQL SET type, string object that can have zero or more values.
134+
/// </summary>
32135
SET = 248,
136+
137+
/// <summary>
138+
/// MySQL TINY_BLOB type, small binary object.
139+
/// </summary>
33140
TINY_BLOB = 249,
141+
142+
/// <summary>
143+
/// MySQL MEDIUM_BLOB type, medium-sized binary object.
144+
/// </summary>
34145
MEDIUM_BLOB = 250,
146+
147+
/// <summary>
148+
/// MySQL LONG_BLOB type, large binary object.
149+
/// </summary>
35150
LONG_BLOB = 251,
151+
152+
/// <summary>
153+
/// MySQL BLOB type, binary large object.
154+
/// </summary>
36155
BLOB = 252,
156+
157+
/// <summary>
158+
/// MySQL VAR_STRING type, variable-length string (deprecated, VARCHAR is used instead).
159+
/// </summary>
37160
VAR_STRING = 253,
161+
162+
/// <summary>
163+
/// MySQL STRING type, fixed-length string.
164+
/// </summary>
38165
STRING = 254,
166+
167+
/// <summary>
168+
/// MySQL GEOMETRY type, for storing geometric data.
169+
/// </summary>
39170
GEOMETRY = 255
40171
}
41172
}

src/SciSharp.MySQL.Replication/Events/FormatDescriptionEvent.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,37 @@
66
namespace SciSharp.MySQL.Replication
77
{
88
/// <summary>
9+
/// Represents a MySQL FORMAT_DESCRIPTION_EVENT that describes the format of the binary log.
10+
/// This event appears at the beginning of each binary log file and provides information
11+
/// about the server version and header lengths for each event type.
912
/// https://dev.mysql.com/doc/internals/en/format-description-event.html
1013
/// </summary>
1114
public sealed class FormatDescriptionEvent : LogEvent
1215
{
16+
/// <summary>
17+
/// Gets or sets the binary log format version.
18+
/// </summary>
1319
public short BinlogVersion { get; set; }
1420

21+
/// <summary>
22+
/// Gets or sets the MySQL server version string.
23+
/// </summary>
1524
public string ServerVersion { get; set; }
1625

26+
/// <summary>
27+
/// Gets or sets the timestamp when the binary log was created.
28+
/// </summary>
1729
public DateTime CreateTimestamp { get; set; }
1830

31+
/// <summary>
32+
/// Gets or sets the length of the event header.
33+
/// </summary>
1934
public byte EventHeaderLength { get; set; }
2035

36+
/// <summary>
37+
/// Gets or sets the array of event type header lengths.
38+
/// Each index corresponds to a LogEventType and contains the header length for that type.
39+
/// </summary>
2140
public byte[] EventTypeHeaderLengths { get; set; }
2241

2342
private string ReadServerVersion(ref SequenceReader<byte> reader, int len)
@@ -49,6 +68,11 @@ private string ReadServerVersion(ref SequenceReader<byte> reader, int len)
4968
}
5069
}
5170

71+
/// <summary>
72+
/// Decodes the body of the event from the binary representation.
73+
/// </summary>
74+
/// <param name="reader">The sequence reader containing the binary data.</param>
75+
/// <param name="context">The context for decoding.</param>
5276
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
5377
{
5478
reader.TryReadLittleEndian(out short version);
@@ -73,6 +97,10 @@ protected internal override void DecodeBody(ref SequenceReader<byte> reader, obj
7397
EventTypeHeaderLengths = eventTypeHeaderLens;
7498
}
7599

100+
/// <summary>
101+
/// Returns a string representation of the FormatDescriptionEvent.
102+
/// </summary>
103+
/// <returns>A string containing event information.</returns>
76104
public override string ToString()
77105
{
78106
return $"{EventType.ToString()}\r\nBinlogVersion: {BinlogVersion}\r\nServerVersion: {ServerVersion}";

src/SciSharp.MySQL.Replication/Events/QueryEvent.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,57 @@
55

66
namespace SciSharp.MySQL.Replication
77
{
8+
/// <summary>
9+
/// Represents a MySQL QUERY_EVENT that contains SQL statements executed on the server.
10+
/// This event is generated for statements like CREATE, ALTER, INSERT, UPDATE, DELETE, etc.
11+
/// that are not using row-based replication format.
12+
/// </summary>
813
public sealed class QueryEvent : LogEvent
914
{
15+
/// <summary>
16+
/// Gets or sets the ID of the thread that executed the query.
17+
/// </summary>
1018
public int SlaveProxyID { get; private set; }
19+
20+
/// <summary>
21+
/// Gets or sets the time in seconds the query took to execute.
22+
/// </summary>
1123
public DateTime ExecutionTime { get; private set; }
24+
25+
/// <summary>
26+
/// Gets or sets the error code returned by the query execution.
27+
/// A value of 0 indicates successful execution.
28+
/// </summary>
1229
public short ErrorCode { get; private set; }
30+
31+
/// <summary>
32+
/// Gets or sets the status variables block.
33+
/// </summary>
1334
public string StatusVars { get; private set; }
35+
36+
/// <summary>
37+
/// Gets or sets the database name that was active when the query was executed.
38+
/// </summary>
1439
public string Schema { get; private set; }
40+
41+
/// <summary>
42+
/// Gets or sets the SQL query text that was executed.
43+
/// </summary>
1544
public String Query { get; private set; }
1645

46+
/// <summary>
47+
/// Initializes a new instance of the <see cref="QueryEvent"/> class.
48+
/// </summary>
1749
public QueryEvent()
1850
{
1951
this.HasCRC = true;
2052
}
2153

54+
/// <summary>
55+
/// Decodes the body of the event from the binary representation.
56+
/// </summary>
57+
/// <param name="reader">The sequence reader containing the binary data.</param>
58+
/// <param name="context">The context for decoding.</param>
2259
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
2360
{
2461
reader.TryReadLittleEndian(out int slaveProxyID);
@@ -45,6 +82,10 @@ protected internal override void DecodeBody(ref SequenceReader<byte> reader, obj
4582
Query = reader.ReadString();
4683
}
4784

85+
/// <summary>
86+
/// Returns a string representation of the QueryEvent.
87+
/// </summary>
88+
/// <returns>A string containing the event type, database name, and SQL query.</returns>
4889
public override string ToString()
4990
{
5091
return $"{EventType.ToString()}\r\nSlaveProxyID: {SlaveProxyID}\r\nExecutionTime: {ExecutionTime}\r\nErrorCode: {ErrorCode}\r\nStatusVars: {StatusVars}\r\nSchema: {Schema}\r\nQuery: {Query}";

src/SciSharp.MySQL.Replication/Events/RotateEvent.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66
namespace SciSharp.MySQL.Replication
77
{
88
/// <summary>
9+
/// Represents a MySQL ROTATE_EVENT that indicates a switch to a new binary log file.
10+
/// This event is generated when the master server switches to a new binary log file,
11+
/// either because the current file reached the max size or due to a manual rotation.
912
/// https://dev.mysql.com/doc/internals/en/rotate-event.html
1013
/// </summary>
1114
public sealed class RotateEvent : LogEvent
1215
{
16+
/// <summary>
17+
/// Gets or sets the position in the new binary log file where the next event starts.
18+
/// </summary>
1319
public long RotatePosition { get; set; }
1420

21+
/// <summary>
22+
/// Gets or sets the name of the new binary log file.
23+
/// </summary>
1524
public string NextBinlogFileName { get; set; }
1625

26+
/// <summary>
27+
/// Decodes the body of the event from the binary representation.
28+
/// </summary>
29+
/// <param name="reader">The sequence reader containing the binary data.</param>
30+
/// <param name="context">The context for decoding.</param>
1731
protected internal override void DecodeBody(ref SequenceReader<byte> reader, object context)
1832
{
1933
reader.TryReadLittleEndian(out long position);
@@ -25,6 +39,10 @@ protected internal override void DecodeBody(ref SequenceReader<byte> reader, obj
2539
reader.Advance(binglogFileNameSize);
2640
}
2741

42+
/// <summary>
43+
/// Returns a string representation of the RotateEvent.
44+
/// </summary>
45+
/// <returns>A string containing the event type, new filename, and position information.</returns>
2846
public override string ToString()
2947
{
3048
return $"{EventType.ToString()}\r\nRotatePosition: {RotatePosition}\r\nNextBinlogFileName: {NextBinlogFileName}";

src/SciSharp.MySQL.Replication/Events/RowSet.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,36 @@
77

88
namespace SciSharp.MySQL.Replication
99
{
10+
/// <summary>
11+
/// Represents a set of rows affected by a row-based replication event.
12+
/// Contains both the column names and the row data.
13+
/// </summary>
1014
public sealed class RowSet
1115
{
16+
/// <summary>
17+
/// Gets or sets the list of column names.
18+
/// </summary>
19+
/// <remarks>
20+
/// May be null if column names are not available in the binlog.
21+
/// </remarks>
1222
public IReadOnlyList<string> ColumnNames { get; set; }
1323

24+
/// <summary>
25+
/// Gets or sets the list of rows.
26+
/// Each row is represented as an array of cell values.
27+
/// </summary>
28+
/// <remarks>
29+
/// For UPDATE_ROWS_EVENT, the cell values are instances of CellValue containing both before and after values.
30+
/// For WRITE_ROWS_EVENT and DELETE_ROWS_EVENT, the cell values are the direct column values.
31+
/// </remarks>
1432
public IReadOnlyList<object[]> Rows { get; set; }
1533

34+
/// <summary>
35+
/// Converts the rows into a readable format as a list of dictionaries.
36+
/// Each dictionary represents a row with column names as keys and cell values as values.
37+
/// </summary>
38+
/// <returns>A list of dictionaries representing the rows.</returns>
39+
/// <exception cref="Exception">Thrown when column names are not available.</exception>
1640
public IReadOnlyList<IDictionary<string, object>> ToReadableRows()
1741
{
1842
var columnNames = ColumnNames;

0 commit comments

Comments
 (0)