-
Notifications
You must be signed in to change notification settings - Fork 694
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: Add support for creating sequence in MariaDB #2324
base: main
Are you sure you want to change the base?
Conversation
I'll fix some tests |
This reverts commit e6bb1df.
TransactionManager.current().db.isVersionCovers(SEQUENCE_MIN_MAJOR_VERSION, SEQUENCE_MIN_MINOR_VERSION) | ||
} | ||
|
||
// actually MariaDb supports it but jdbc driver prepares statement without RETURNING clause |
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.
Should we implement this by ourselves? I looked how Oracle do this. As I understand Exposed sends sql without returning clause and jdbc driver add it after.
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.
Hi @devgor88. Thank you for your contribution! I left some comments.
override fun sequences(): List<String> { | ||
val sequences = mutableListOf<String>() | ||
TransactionManager.current().exec("SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES") { rs -> | ||
while (rs.next()) { | ||
sequences.add(rs.getString("SEQUENCE_NAME")) | ||
} | ||
} | ||
return sequences | ||
} |
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.
Why is overriding this function necessary? I tested your changes with MariaDB 10.3, and this was not needed.
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.
I've tested it again with MariaDB 10.3 and
const val SEQUENCE_MIN_MAJOR_VERSION = 10
const val SEQUENCE_MIN_MINOR_VERSION = 3
At least several tests are fail. Especially important is org.jetbrains.exposed.sql.tests.shared.ddl.SequencesTests#testManuallyCreatedSequenceExists
Overriding can be omitted for versions between 10.3 and 11.5 because it and its super functions return empty list. For versions more or equal 11.5 it can be omitted too because super function is working correctly but I'd left it because super version run this query
SELECT TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM, TABLE_NAME, IF(TABLE_TYPE='BASE TABLE' or TABLE_TYPE='SYSTEM VERSIONED', 'TABLE', IF(TABLE_TYPE='TEMPORARY', 'LOCAL TEMPORARY', TABLE_TYPE)) as TABLE_TYPE, TABLE_COMMENT REMARKS, NULL TYPE_CAT, NULL TYPE_SCHEM, NULL TYPE_NAME, NULL SELF_REFERENCING_COL_NAME, NULL REF_GENERATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE IN ('SEQUENCE') ORDER BY TABLE_TYPE, TABLE_SCHEMA, TABLE_NAME
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.
What tests are failing for you?
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.
I rerun them again and none of sequence related tests are failing.
const val SEQUENCE_MIN_MAJOR_VERSION = 11 | ||
const val SEQUENCE_MIN_MINOR_VERSION = 5 |
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.
If it's possible to get a list of sequences from version 10.3 and without overriding the sequences()
function above, then this can be changed from 11.5 to 10.3.
Hi @joc-a. Thank you for reviewing my contribution. I answered your comments. |
Description
Summary of the change: Add support for creating sequence in MariaDB.
Detailed description:
What: Variable supportsCreateSequence overrided from MysqlDialect(). Now it checks db version and return true for version upper or equal than
10.311.5 (sequences is supported from 10.3 but we can get list of them only starting with 11.5).Why: It was necessary because existing isVersionCovers compares version as BigDecimal. Due to it 10.11 < 10.3.
How: There were added majorVersion and minorVersion in ExposedDatabaseMetadata. They were implemented in JdbcDatabaseMetadataImpl. isVersionCovers function implemented with two parameters major and minor versions.
Type of Change
Please mark the relevant options with an "X":
Updates/remove existing public API methods:
Affected databases:
Checklist
Related Issues