-
Notifications
You must be signed in to change notification settings - Fork 1
MySQL修正 #58
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
MySQL修正 #58
Changes from all commits
70515bd
7e9bed9
db174e0
87990f6
22ea4ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,9 +235,11 @@ class MySQLCassette { | |
| if (options && options.clean) { | ||
| try { | ||
| let tables = await conn.raw("SHOW TABLES"); | ||
| await conn.raw("SET foreign_key_checks = 0"); | ||
| for (let table of tables[0]) { | ||
| await conn.raw(`DROP TABLE IF EXISTS ${table.Tables_in_track} CASCADE`); | ||
| await conn.raw(`DROP TABLE IF EXISTS ${table.Tables_in_track}`); | ||
| } | ||
| await conn.raw("SET foreign_key_checks = 1"); | ||
|
Comment on lines
+238
to
+242
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. テーブルを削除する際に、外部キーをオフにしてから、削除するようにしました。
|
||
| } catch (e2) { console.error(e2); } | ||
| } | ||
| return conn; | ||
|
|
@@ -267,21 +269,22 @@ class MySQLCassette { | |
| `; | ||
| } | ||
| updateAutoIncrementSql(table, column) { | ||
| return `ALTER TABLE ${table} AUTO_INCREMENT = ? + 1`; | ||
| return `ALTER TABLE ${table} AUTO_INCREMENT = ?`; | ||
|
Comment on lines
-270
to
+272
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MySQLではプレースホルダを使った計算式はエラーが出るようなので、
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 既存のSQLiteチャレンジでも、影響なく正常に動作することを確認です。 |
||
| } | ||
| lastValueSql(table, idCol) { | ||
| return `SELECT * FROM ${table} WHERE ${idCol} = LAST_INSERT_ID()`; | ||
| } | ||
| async listFk(table, conn) { | ||
| return await conn.query(` | ||
| SELECT | ||
| kcu.column_name AS column, | ||
| ccu.table_name AS foreign_table, | ||
| ccu.column_name AS foreign_column | ||
| FROM information_schema.table_constraints AS tc | ||
| INNER JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name | ||
| INNER JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name | ||
| WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = '${table}' | ||
| COLUMN_NAME AS \`column\`, | ||
| REFERENCED_TABLE_NAME AS foreign_table, | ||
| REFERENCED_COLUMN_NAME AS foreign_column | ||
| FROM information_schema.KEY_COLUMN_USAGE | ||
| WHERE | ||
| TABLE_SCHEMA = DATABASE() | ||
| AND TABLE_NAME = '${table}' | ||
| AND REFERENCED_TABLE_NAME IS NOT NULL | ||
|
Comment on lines
-278
to
+287
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. listFkのSQL文をMySQLのものに修正しました。
|
||
| `); | ||
| } | ||
| errorOf(e) { | ||
|
|
@@ -591,6 +594,9 @@ class Connection { | |
|
|
||
| async updateAutoIncrement(table, column, count) { | ||
| const sql = this._cassette.updateAutoIncrementSql(table, column); | ||
| if (this._cassette instanceof MySQLCassette) { | ||
| count = (count || 0) + 1; | ||
| } | ||
| return await this.query(sql, [count]); | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugコマンドのUSAGEのclientオプションにmysqlを追加しました。