File: mysqlx_resultset.proto

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (629 lines) | stat: -rw-r--r-- 20,077 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*
 * Copyright (c) 2015, 2025, Oracle and/or its affiliates.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2.0,
 * as published by the Free Software Foundation.
 *
 * This program is designed to work with certain software (including
 * but not limited to OpenSSL) that is licensed under separate terms,
 * as designated in a particular file or component or in included license
 * documentation.  The authors of MySQL hereby grant you an additional
 * permission to link the program and your derivative works with the
 * separately licensed software that they have either included with
 * the program or referenced in the documentation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License, version 2.0, for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */
syntax = "proto2";

import "mysqlx.proto"; // comment_out_if PROTOBUF_LITE

// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;

/**
@namespace Mysqlx::Resultset
@brief Resultsets

Executing a statement against the server may result in zero or more
Resultsets followed by zero or one Resultset of the ``OUT`` parameters.

A Resultset consists of:

- one or more @ref Mysqlx::Resultset::ColumnMetaData
- zero or more @ref Mysqlx::Resultset::Row

It is followed by:

- a @ref Mysqlx::Resultset::FetchDoneMoreResultsets if more
  resultsets are following
- a @ref Mysqlx::Resultset::FetchDoneMoreOutParams if more
  Resultset of ``OUT`` parameters is following
- a @ref Mysqlx::Resultset::FetchDone if the last resultset
  was sent

@startuml
  ...
  loop has more resultsets or not at end of fetch
    group resultset
      loop has more columns
        server --> client: ColumnMetaData
      end
      loop has more rows
        server --> client: Row
      end
    end
    alt has more resultsets
      server --> client: FetchDoneMoreResultsets
    end
  end
  loop has more OUT-paramsets or not at end of fetch
    server --> client: FetchDoneMoreOutParams
    group resultset
      loop has more columns
        server --> client: ColumnMetaData
      end
      loop has more rows
        server --> client: Row
      end
    end
  end
  alt at end of all resultsets
    server --> client: FetchDone
  else cursor is opened
    server --> client: FetchSuspended
  end
  ...
@enduml

@par Examples:

@par No Resultset

A ``INSERT`` statement usually doesn't send any resultset which
results in only a ``FetchDone``.

@startuml
  server --> client: FetchDone
@enduml

@par Empty Resultset

``SELECT 1 LIMIT 0`` results in a empty resultset:

@startuml
  server --> client: ColumnMetaData(.name = "1", .type = INT)
  server --> client: FetchDone
@enduml

@par Multi Resultset

``CALL`` may result in multiple resultsets.

@startuml
  server --> client: ColumnMetaData(.name = "1", .type = INT)
  server --> client: Row
  server --> client: FetchDoneMoreResultsets
  server --> client: ColumnMetaData(.name = "1", .type = INT)
  server --> client: Row
  server --> client: FetchDone
@enduml

@par OUT params

``CALL`` may result OUT parameters only

@startuml
  server --> client: FetchDoneMoreOutParams
  server --> client: ColumnMetaData(.name = "1", .type = INT)
  server --> client: Row
  server --> client: FetchDone
@enduml
*/

package Mysqlx.Resultset;
option java_package = "com.mysql.cj.x.protobuf";

/**
Resultsets are finished, OUT paramset is next:
*/
message FetchDoneMoreOutParams {
  option (server_message_id) = RESULTSET_FETCH_DONE_MORE_OUT_PARAMS; // comment_out_if PROTOBUF_LITE
}

/**
Resultset and out-params are finished, but more resultsets available
*/
message FetchDoneMoreResultsets {
  option (server_message_id) = RESULTSET_FETCH_DONE_MORE_RESULTSETS; // comment_out_if PROTOBUF_LITE
}

/**
All resultsets are finished
*/
message FetchDone {
  option (server_message_id) = RESULTSET_FETCH_DONE; // comment_out_if PROTOBUF_LITE
}

/**
Cursor is opened; still, the execution of PrepFetch or PrepExecute ended
*/
message FetchSuspended {
  option (server_message_id) = RESULTSET_FETCH_SUSPENDED; // comment_out_if PROTOBUF_LITE
}

/**
Meta data of a column

@note
    The encoding used for the different ``bytes`` fields in the
    meta data is externally controlled. See also:
    https://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

@par
@note
    The server may not set the ``original_{table|name}`` fields
    if they are equal to the plain ``{table|name}`` field.

@par
@note
    A client has to reconstruct it like:
    @code{py}
        if .original_name is empty and .name is not empty:
          .original_name = .name

        if .original_table is empty and .table is not empty:
          .original_table = .table
    @endcode

@par
@note
    ``Compact metadata format`` can be requested by the client.
    In that case, only ``.type`` is set and all other fields are  empty.


Expected data type of Mysqlx.Resultset.Row per SQL Type for
non-NULL values:

| SQL Type          | .type     | .length | .frac\_dig | .flags | .charset |
|-------------------|-----------|---------|------------|--------|----------|
| TINY              | SINT      | x       |            |        |          |
| TINY UNSIGNED     | UINT      | x       |            | x      |          |
| SHORT             | SINT      | x       |            |        |          |
| SHORT UNSIGNED    | UINT      | x       |            | x      |          |
| INT24             | SINT      | x       |            |        |          |
| INT24 UNSIGNED    | UINT      | x       |            | x      |          |
| INT               | SINT      | x       |            |        |          |
| INT UNSIGNED      | UINT      | x       |            | x      |          |
| LONGLONG          | SINT      | x       |            |        |          |
| LONGLONG UNSIGNED | UINT      | x       |            | x      |          |
| DOUBLE            | DOUBLE    | x       | x          | x      |          |
| FLOAT             | FLOAT     | x       | x          | x      |          |
| DECIMAL           | DECIMAL   | x       | x          | x      |          |
| VARCHAR,CHAR,...  | BYTES     | x       |            | x      | x        |
| GEOMETRY          | BYTES     |         |            |        |          |
| TIME              | TIME      | x       |            |        |          |
| DATE              | DATETIME  | x       |            |        |          |
| DATETIME          | DATETIME  | x       |            |        |          |
| YEAR              | UINT      | x       |            | x      |          |
| TIMESTAMP         | DATETIME  | x       |            |        |          |
| SET               | SET       |         |            |        | x        |
| ENUM              | ENUM      |         |            |        | x        |
| NULL              | BYTES     |         |            |        |          |
| BIT               | BIT       | x       |            |        |          |

@note
     The SQL "NULL" value is sent as an empty field value in
     @ref Mysqlx::Resultset::Row.

@par Tip
     The protobuf encoding of primitive data types is described in
     https://developers.google.com/protocol-buffers/docs/encoding

+ SINT

   - ``.length`` @n
        Maximum number of displayable decimal digits (including
        minus sign) of the type.
        @note
            The valid range is 0-255, but usually you'll see 1-20.

        | SQL Type         | Maximum Digits per Type |
        |------------------|-------------------------|
        | TINY SIGNED      | 4                       |
        | SHORT SIGNED     | 6                       |
        | INT24 SIGNED     | 8                       |
        | INT SIGNED       | 11                      |
        | LONGLONG SIGNED  | 20                      |

        @par Tip
            Definition of ``M`` are in
            https://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html.

   - ``value``@n
        Variable length encoded signed 64 integer.

+ UINT

   - ``.flags & 1`` (zerofill) @n
        The client has to left pad with 0's up to .length.

   - ``.length`` @n
        Maximum number of displayable decimal digits of the
        type.
       @note
            The valid range is 0-255, but usually you'll see
            1-20.

        | SQL Type             | max digits per type |
        |----------------------|---------------------|
        | TINY UNSIGNED        | 3                   |
        | SHORT UNSIGNED       | 5                   |
        | INT24 UNSIGNED       | 8                   |
        | INT UNSIGNED         | 10                  |
        | LONGLONG UNSIGNED    | 20                  |

        @par Tip
            Definition of ``M`` are in
            https://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html.

   - ``value`` @n
        Variable length encoded unsigned 64 integer.

+ BIT

   - ``.length`` @n
        Maximum number of displayable binary digits.
        @note
            The valid range for M of the ``BIT`` type is 1 - 64.

        @par Tip
            https://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

   - ``value`` @n
        Variable length encoded unsigned 64 integer.

+ DOUBLE

   - ``.length`` @n
        Maximum number of displayable decimal digits (including
        the decimal point and ``.fractional_digits``).

   - ``.fractional_digits`` @n
        Maximum number of displayable decimal digits following
        the decimal point.

   - ``value``@n
        Encoded as protobuf's 'double'.

+ FLOAT

   - ``.length``@n
        Maximum number of displayable decimal digits (including
        the decimal point and ``.fractional_digits``).

   - ``.fractional_digits``@n
        Maximum number of displayable decimal digits following
        the decimal point.

   - ``value``@n
        Encoded as protobuf's 'float'.

+ BYTES, ENUM
    @note
        BYTES is used for all opaque byte strings that may have a charset:
        -  TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB
        -  TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
        -  VARCHAR, VARBINARY
        -  CHAR, BINARY
        -  ENUM

   - ``.length``@n
        Maximum length of characters of the underlying type.

   - ``.flags & 1`` (rightpad) @n
        If the length of the field is less than ``.length``, the
        receiver is supposed to add padding characters to the
        right end of the string. If the ``.charset`` is
        "binary", the padding character is ``0x00``, otherwise
        it is a space character as defined by that character
        set.
        | SQL Type      | .length  | .charset  | .flags   |
        |---------------|----------|-----------|----------|
        | TINYBLOB      | 256      | binary    |          |
        | BLOB          | 65535    | binary    |          |
        | VARCHAR(32)   | 32       | utf8      |          |
        | VARBINARY(32) | 32       | utf8\_bin |          |
        | BINARY(32)    | 32       | binary    | rightpad |
        | CHAR(32)      | 32       | utf8      | rightpad |

   - ``value``
        Sequence of bytes with added one extra ``0x00`` byte at
        the end. To obtain the original string, the extra
        ``0x00`` should be removed. The length of the string can
        be acquired with protobuf's field ``length()`` method:

        ``length of sequence-of-bytes = length-of-field - 1``
        @note
            The extra byte allows to distinguish between a NULL
            and empty byte sequence.

+ TIME

    A time value.

   - ``value``@n
        The following bytes sequence:

        ``negate [ hour [ minutes [ seconds [ useconds ]]]]``

        -  negate - one byte, should be one of: 0x00 for "+",
           0x01 for "-"

        -  hour - optional variable length encoded unsigned64
           value for the hour

        -  minutes - optional variable length encoded unsigned64
           value for the minutes

        -  seconds - optional variable length encoded unsigned64
           value for the seconds

        -  useconds - optional variable length encoded
           unsigned64 value for the microseconds

            @par Tip
            The protobuf encoding in
            https://developers.google.com/protocol-buffers/docs/encoding.

            @note
            Hour, minutes, seconds, and useconds are optional if
            all the values to the right are 0.

        Example: ``0x00 -> +00:00:00.000000``

+ DATETIME

    A date or date and time value.

   - ``value`` @n
        A sequence of variants, arranged as follows:

        ``| year | month | day | [ | hour | [ | minutes | [ | seconds | [ | useconds | ]]]]``

        -  year - variable length encoded unsigned64 value for
           the year

        -  month - variable length encoded unsigned64 value for
           the month

        -  day - variable length encoded unsigned64 value for
           the day

        -  hour - optional variable length encoded unsigned64
           value for the hour

        -  minutes - optional variable length encoded unsigned64
           value for the minutes

        -  seconds - optional variable length encoded unsigned64
           value for the seconds

        -  useconds - optional variable length encoded
           unsigned64 value for the microseconds
           @note
            Hour, minutes, seconds, useconds are optional if all
            the values to the right are 0.

   - ``.flags``@n
    | Name          | Position |
    |---------------|----------|
    | is\_timestamp | 1        |

+ DECIMAL

    An arbitrary length number. The number is encoded as a
    single byte indicating the position of the decimal point
    followed by the Packed BCD encoded number. Packed BCD is
    used to simplify conversion to and from strings and other
    native arbitrary precision math data types. See also: packed
    BCD in https://en.wikipedia.org/wiki/Binary-coded_decimal

   - ``.length``
        Maximum number of displayable decimal digits
        (*excluding* the decimal point and sign, but including
        ``.fractional_digits``).
        @note
            Should be in the range of 1 - 65.

   - ``.fractional_digits``
        The decimal digits to display out of length.
        @note
            Should be in the range of 0 - 30.

    ``value``
        The following bytes sequence:

        ``scale | BCD+ sign [0x00]?``

        -  scale - 8bit scale value (number of decimal digit after the '.')

        -  BCD - BCD encoded digits (4 bits for each digit)

        -  sign - sign encoded on 4 bits (0xc = "+", 0xd = "-")

        -  0x0 - last 4bits if length(digits) % 2 == 0

        Example: ``x04 0x12 0x34 0x01
                                        0xd0 -> -12.3401``

+ SET

    A list of strings representing a SET of values.

   - ``value``@n
        A sequence of 0 or more of protobuf's bytes (length
        prepended octets) or one of the special sequences with a
        predefined meaning listed below.

        Example (length of the bytes array shown in brackets):
            -  ``[0]`` - the NULL value

            -  ``[1] 0x00`` - a set containing a blank string ''

            -  ``[1] 0x01`` - this would be an invalid value,
               but is to be treated as the empty set

            -  ``[2] 0x01 0x00`` - a set with a single item, which is the '0'
               character

            -  ``[8] 0x03 F O O 0x03 B A R`` - a set with 2 items: FOO,BAR
*/
message ColumnMetaData {
  enum FieldType {
    SINT     = 1;
    UINT     = 2;

    DOUBLE   = 5;
    FLOAT    = 6;

    BYTES    = 7;

    TIME     = 10;
    DATETIME = 12;
    SET      = 15;
    ENUM     = 16;
    BIT      = 17;

    DECIMAL  = 18;
  }

  /** datatype of the field in a row */
  required FieldType type = 1;

  /** name of the column */
  optional bytes name = 2;

  /** name of the column before an alias was applied */
  optional bytes original_name = 3;

  /** name of the table the column originates from */
  optional bytes table = 4;

  /** name of the table the column originates from before an alias was applied */
  optional bytes original_table = 5;

  /** schema the column originates from */
  optional bytes schema = 6;

  /** catalog the schema originates from
      @note
        As there is currently no support for catalogs in MySQL,
        don't expect this field to be set. In the MySQL C/S
        protocol the field had the value ``def`` all the time */
  optional bytes catalog = 7;

  optional uint64 collation = 8 /* ifdef PROTOBUF3 [jstype = JS_STRING] */;

  /** displayed factional decimal digits for floating point and
      fixed point numbers */
  optional uint32 fractional_digits = 9;

  /** maximum count of displayable characters of .type */
  optional uint32 length = 10;

  /** ``.type`` specific flags
      | Type    | Value  | Description  |
      |---------|--------|--------------|
      | UINT    | 0x0001 | zerofill     |
      | DOUBLE  | 0x0001 | unsigned     |
      | FLOAT   | 0x0001 | unsigned     |
      | DECIMAL | 0x0001 | unsigned     |
      | BYTES   | 0x0001 | rightpad     |

      | Value  | Description     |
      |--------|-----------------|
      | 0x0010 | NOT\_NULL       |
      | 0x0020 | PRIMARY\_KEY    |
      | 0x0040 | UNIQUE\_KEY     |
      | 0x0080 | MULTIPLE\_KEY   |
      | 0x0100 | AUTO\_INCREMENT |

      default: 0 */
  optional uint32 flags = 11;

  /** a hint about the higher-level encoding of a BYTES field
      | Type   | Value  | Description             |
      |--------|--------|-------------------------|
      | BYTES  | 0x0001 | GEOMETRY (WKB encoding) |
      | BYTES  | 0x0002 | JSON (text encoding)    |
      | BYTES  | 0x0003 | XML (text encoding)     |
      @note
        This list isn't comprehensive. As a guideline: the field's
        value is expected to pass a validator check on client
        and server if this field is set. If the server adds more
        internal data types that rely on BLOB storage like image
        manipulation, seeking into complex types in BLOBs, and
        more types will be added */
  optional uint32 content_type = 12;

  option (server_message_id) = RESULTSET_COLUMN_META_DATA; // comment_out_if PROTOBUF_LITE
}

/**
Row in a Resultset.

A row is represented as a list of fields encoded as byte blobs.
Value of each field is encoded as sequence of bytes using
encoding appropriate for the type of the value given by
``ColumnMetadata``, as specified in the @ref Mysqlx::Resultset::ColumnMetaData
description.
*/
message Row {
  repeated bytes field = 1;

  option (server_message_id) = RESULTSET_ROW; // comment_out_if PROTOBUF_LITE
}


/**
A hint about the higher-level encoding of a BYTES field

|type  | value  | description             |
|------| -------|-------------------------|
|BYTES | 0x0001 | GEOMETRY (WKB encoding) |
|BYTES | 0x0002 | JSON (text encoding)    |
|BYTES | 0x0003 | XML (text encoding)     |

@note
  this list isn't comprehensive. As a guideline: the field's value is expected
  to pass a validator check on client and server if this field is set.
  If the server adds more internal datatypes that rely on BLOB storage
  like image manipulation, seeking into complex types in BLOBs, ... more
  types will be added.
*/
enum ContentType_BYTES {
  GEOMETRY = 1;
  JSON = 2;
  XML = 3;
}

/**
A hint about the higher-level encoding of a DATETIME field

|type     |value  |description                                |
|---------|-------|-------------------------------------------|
|DATE     |0x0001 |DATETIME contains only date part           |
|DATETIME |0x0002 |DATETIME contains both date and time parts |
*/
enum ContentType_DATETIME {
  DATE = 1;
  DATETIME = 2;
}