Skip to content

Commit f91e9ee

Browse files
committed
Add restrictions to 'Tables' schema.
Signed-off-by: Bradley Grainger <bgrainger@gmail.com>
1 parent 0bf25b9 commit f91e9ee

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

docs/content/overview/schema-collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
date: 2021-04-24
3-
lastmod: 2022-07-11
3+
lastmod: 2022-08-12
44
menu:
55
main:
66
parent: getting started
@@ -37,7 +37,7 @@ weight: 80
3737
* `ResourceGroups`
3838
* `Restrictions`[information about the restrictions supported when retrieving schemas](../schema/restrictions/)
3939
* `SchemaPrivileges`
40-
* `Tables`
40+
* `Tables`[information about tables](../schema/tables/)
4141
* `TableConstraints`
4242
* `TablePrivileges`
4343
* `TableSpaces`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
date: 2022-07-10
3+
lastmod: 2022-08-12
4+
title: Tables Schema
5+
---
6+
7+
# Tables Schema
8+
9+
The `Tables` schema provides information about tables.
10+
11+
Column Name | Data Type | Description
12+
--- | --- | ---
13+
TABLE_CATALOG | string |
14+
TABLE_SCHEMA | string |
15+
TABLE_NAME | string |
16+
TABLE_TYPE | string |
17+
ENGINE | string |
18+
VERSION | string |
19+
ROW_FORMAT | string |
20+
TABLE_ROWS | long |
21+
AVG_ROW_LENGTH | long |
22+
DATA_LENGTH | long |
23+
MAX_DATA_LENGTH | long |
24+
INDEX_LENGTH | long |
25+
DATA_FREE | long |
26+
AUTO_INCREMENT | long |
27+
CREATE_TIME | DateTime |
28+
UPDATE_TIME | DateTime |
29+
CHECK_TIME | DateTime |
30+
TABLE_COLLATION | string |
31+
CHECKSUM | string |
32+
CREATE_OPTIONS | string |
33+
TABLE_COMMENT | string |
34+
35+
The following restrictions are supported:
36+
37+
Restriction Name | Restriction Default | Restriction Number
38+
--- | --- | --:
39+
Catalog | TABLE_CATALOG | 1
40+
Schema | TABLE_SCHEMA | 2
41+
Table | TABLE_NAME | 3
42+
TableType | TABLE_TYPE | 4
43+

src/MySqlConnector/Core/SchemaProvider.g.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private Task FillMetaDataCollectionsAsync(IOBehavior ioBehavior, DataTable dataT
111111
dataTable.Rows.Add("ResourceGroups", 0, 0);
112112
dataTable.Rows.Add("Restrictions", 0, 0);
113113
dataTable.Rows.Add("SchemaPrivileges", 0, 0);
114-
dataTable.Rows.Add("Tables", 0, 3);
114+
dataTable.Rows.Add("Tables", 4, 3);
115115
dataTable.Rows.Add("TableConstraints", 0, 3);
116116
dataTable.Rows.Add("TablePrivileges", 0, 0);
117117
dataTable.Rows.Add("TableSpaces", 0, 0);
@@ -599,6 +599,10 @@ private Task FillRestrictionsAsync(IOBehavior ioBehavior, DataTable dataTable, s
599599
dataTable.Rows.Add("Columns", "Schema", "TABLE_SCHEMA", 2);
600600
dataTable.Rows.Add("Columns", "Table", "TABLE_NAME", 3);
601601
dataTable.Rows.Add("Columns", "Column", "COLUMN_NAME", 4);
602+
dataTable.Rows.Add("Tables", "Catalog", "TABLE_CATALOG", 1);
603+
dataTable.Rows.Add("Tables", "Schema", "TABLE_SCHEMA", 2);
604+
dataTable.Rows.Add("Tables", "Table", "TABLE_NAME", 3);
605+
dataTable.Rows.Add("Tables", "TableType", "TABLE_TYPE", 4);
602606

603607
return Utility.CompletedTask;
604608
}
@@ -622,8 +626,8 @@ private async Task FillSchemaPrivilegesAsync(IOBehavior ioBehavior, DataTable da
622626

623627
private async Task FillTablesAsync(IOBehavior ioBehavior, DataTable dataTable, string?[]? restrictionValues, CancellationToken cancellationToken)
624628
{
625-
if (restrictionValues is not null)
626-
throw new ArgumentException("restrictionValues is not supported for schema 'Tables'.", nameof(restrictionValues));
629+
if (restrictionValues is { Length: > 4 })
630+
throw new ArgumentException("More than 4 restrictionValues are not supported for schema 'Tables'.", nameof(restrictionValues));
627631

628632
dataTable.Columns.AddRange(new DataColumn[]
629633
{
@@ -650,7 +654,20 @@ private async Task FillTablesAsync(IOBehavior ioBehavior, DataTable dataTable, s
650654
new("TABLE_COMMENT", typeof(string)),
651655
});
652656

653-
await FillDataTableAsync(ioBehavior, dataTable, "TABLES", null, cancellationToken).ConfigureAwait(false);
657+
var columns = new List<KeyValuePair<string, string>>();
658+
if (restrictionValues is not null)
659+
{
660+
if (restrictionValues.Length > 0 && !string.IsNullOrEmpty(restrictionValues[0]))
661+
columns.Add(new("TABLE_CATALOG", restrictionValues[0]!));
662+
if (restrictionValues.Length > 1 && !string.IsNullOrEmpty(restrictionValues[1]))
663+
columns.Add(new("TABLE_SCHEMA", restrictionValues[1]!));
664+
if (restrictionValues.Length > 2 && !string.IsNullOrEmpty(restrictionValues[2]))
665+
columns.Add(new("TABLE_NAME", restrictionValues[2]!));
666+
if (restrictionValues.Length > 3 && !string.IsNullOrEmpty(restrictionValues[3]))
667+
columns.Add(new("TABLE_TYPE", restrictionValues[3]!));
668+
}
669+
670+
await FillDataTableAsync(ioBehavior, dataTable, "TABLES", columns, cancellationToken).ConfigureAwait(false);
654671
}
655672

656673
private async Task FillTableConstraintsAsync(IOBehavior ioBehavior, DataTable dataTable, string?[]? restrictionValues, CancellationToken cancellationToken)

tools/SchemaCollectionGenerator/SchemaCollections.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,16 @@
565565
- name: Tables
566566
table: TABLES
567567
identifierPartCount: 3
568+
description: information about tables
569+
restrictions:
570+
- name: Catalog
571+
default: TABLE_CATALOG
572+
- name: Schema
573+
default: TABLE_SCHEMA
574+
- name: Table
575+
default: TABLE_NAME
576+
- name: TableType
577+
default: TABLE_TYPE
568578
columns:
569579
- name: TABLE_CATALOG
570580
type: string

0 commit comments

Comments
 (0)