Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when hyphen-table #126

Merged
merged 4 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions datasource/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ var tests = []struct {
tableCount int
relationCount int
}{
{"my://root:mypass@localhost:33306/testdb", "testdb", 8, 6},
{"pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable", "testdb", 9, 7},
{"my://root:mypass@localhost:33306/testdb", "testdb", 9, 6},
{"pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable", "testdb", 10, 7},
{"json://../testdata/testdb.json", "testdb", 7, 9},
{"ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb", "testdb", 8, 6},
{"ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb", "testdb", 9, 6},
}

func TestMain(m *testing.M) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SELECT table_name, table_type, table_comment FROM information_schema.tables WHER

// table definition
if tableType == "BASE TABLE" {
tableDefRows, err := m.db.Query(fmt.Sprintf("SHOW CREATE TABLE %s", tableName))
tableDefRows, err := m.db.Query(fmt.Sprintf("SHOW CREATE TABLE `%s`", tableName))
defer tableDefRows.Close()
if err != nil {
return errors.WithStack(err)
Expand Down
6 changes: 3 additions & 3 deletions drivers/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ WHERE name != 'sqlite_sequence' AND (type = 'table' OR type = 'view');`)
constraints := []*schema.Constraint{}

// columns
columnRows, err := l.db.Query(fmt.Sprintf("PRAGMA table_info(%s)", tableName))
columnRows, err := l.db.Query(fmt.Sprintf("PRAGMA table_info(`%s`)", tableName))
defer columnRows.Close()
if err != nil {
return errors.WithStack(err)
Expand Down Expand Up @@ -132,7 +132,7 @@ WHERE name != 'sqlite_sequence' AND (type = 'table' OR type = 'view');`)
fkMap := map[string]*fk{}
fkSlice := []*fk{}

foreignKeyRows, err := l.db.Query(fmt.Sprintf("PRAGMA foreign_key_list(%s)", tableName))
foreignKeyRows, err := l.db.Query(fmt.Sprintf("PRAGMA foreign_key_list(`%s`)", tableName))
defer foreignKeyRows.Close()
if err != nil {
return errors.WithStack(err)
Expand Down Expand Up @@ -207,7 +207,7 @@ WHERE name != 'sqlite_sequence' AND (type = 'table' OR type = 'view');`)
}

// indexes and constraints(UNIQUE, PRIMARY KEY)
indexRows, err := l.db.Query(fmt.Sprintf("PRAGMA index_list(%s)", tableName))
indexRows, err := l.db.Query(fmt.Sprintf("PRAGMA index_list(`%s`)", tableName))
defer indexRows.Close()
if err != nil {
return errors.WithStack(err)
Expand Down
1 change: 1 addition & 0 deletions sample/adjust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [administrator.blogs](administrator.blogs.md) | 6 | | BASE TABLE |

## Relations
Expand Down
19 changes: 19 additions & 0 deletions sample/adjust/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hyphen-table

## Description

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ------------- | --------------------------- | ------------------ | -------- | -------- | ------- | ------- |
| id | uuid | uuid_generate_v4() | false | | | |
| hyphen-column | text | | false | | | |
| created | timestamp without time zone | | false | | | |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/adjust/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/adjust/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/exclude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| ---- | ------- | ------- | ---- |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
| [user_options](user_options.md) | 4 | User options table | BASE TABLE |
Expand Down
45 changes: 45 additions & 0 deletions sample/exclude/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# hyphen-table

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `hyphen-table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`hyphen-column` text NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
```

</details>

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | bigint(20) | | false | | | |
| hyphen-column | text | | false | | | |
| created | datetime | | false | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/exclude/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/exclude/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| [logs](logs.md) | 7 | audit log table | BASIC TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [CamelizeTable](CamelizeTable.md) | 2 | | BASIC TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASIC TABLE |

## Relations

Expand Down
19 changes: 19 additions & 0 deletions sample/mssql/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hyphen-table

## Description

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | int | | false | | | |
| hyphen-column | text | | false | | | |
| created | date | | false | | | |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/mssql/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mssql/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
Expand Down
45 changes: 45 additions & 0 deletions sample/mysql/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# hyphen-table

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `hyphen-table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`hyphen-column` text NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
```

</details>

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | bigint(20) | | false | | | |
| hyphen-column | text | | false | | | |
| created | datetime | | false | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/mysql/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/mysql8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
Expand Down
45 changes: 45 additions & 0 deletions sample/mysql8/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# hyphen-table

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `hyphen-table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`hyphen-column` text NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
```

</details>

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | bigint(20) | | false | | | |
| hyphen-column | text | | false | | | |
| created | datetime | | false | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/mysql8/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mysql8/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [administrator.blogs](administrator.blogs.md) | 6 | | BASE TABLE |

## Relations
Expand Down
19 changes: 19 additions & 0 deletions sample/postgres/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hyphen-table

## Description

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | uuid | uuid_generate_v4() | false | | | |
| hyphen-column | text | | false | | | |
| created | timestamp without time zone | | false | | | |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/postgres/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/postgres/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/sqlite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| [logs](logs.md) | 7 | audit log table | table |
| [post_comments](post_comments.md) | 7 | post and comments View table | view |
| [CamelizeTable](CamelizeTable.md) | 2 | | table |
| [hyphen-table](hyphen-table.md) | 3 | | table |
| [check_constraints](check_constraints.md) | 6 | | table |
| [syslog](syslog.md) | 1 | | virtual table |
| [access_log](access_log.md) | 1 | | virtual table |
Expand Down
38 changes: 38 additions & 0 deletions sample/sqlite/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# hyphen-table

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE 'hyphen-table' (
id INTEGER PRIMARY KEY AUTOINCREMENT,
'hyphen-column' TEXT NOT NULL,
created NUMERIC NOT NULL
)
```

</details>

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | INTEGER | | true | | | |
| hyphen-column | TEXT | | false | | | |
| created | NUMERIC | | false | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| id | PRIMARY KEY | PRIMARY KEY (id) |

## Relations

![er](hyphen-table.png)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Binary file added sample/sqlite/hyphen-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/sqlite/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sample/svg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
Expand Down
45 changes: 45 additions & 0 deletions sample/svg/hyphen-table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# hyphen-table

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `hyphen-table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`hyphen-column` text NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
```

</details>

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| id | bigint(20) | | false | | | |
| hyphen-column | text | | false | | | |
| created | datetime | | false | | | |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations

![er](hyphen-table.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
Loading