-
Notifications
You must be signed in to change notification settings - Fork 23
feat: database version query #308
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
Changes from all commits
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -174,6 +174,19 @@ def query_get_table_metadata(self) -> List[str]: | |||||||||||||||||||
| """ | ||||||||||||||||||||
| return inspect(self.connection.engine).get_table_names() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def query_get_database_version(self) -> str: | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Get the database version | ||||||||||||||||||||
| :return: version number | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| query = "SELECT @@version" | ||||||||||||||||||||
| result = self.fetchone(query)[0] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if result: | ||||||||||||||||||||
| return result | ||||||||||||||||||||
|
Comment on lines
+182
to
+186
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. Defensive-programming: guard against
- result = self.fetchone(query)[0]
-
- if result:
- return result
+ row = self.fetchone(query)
+ if row and len(row) > 0 and row[0]:
+ return row[0]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| return "Unknown version" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def query_get_row_count(self, table: str, filters: str = None) -> int: | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Get the row count | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
🛠️ Refactor suggestion
Hard-coding
SELECT @@versionlimits engine support@@versionis SQL-Server / Sybase-specific.SQLDataSourceis dialect-agnostic, so subclasses pointing at Postgres, MySQL, etc. will break.Consider:
self.connection.engine.name) and issuing the appropriate query (SELECT version()for Postgres/MySQL,PRAGMA user_versionfor SQLite, etc.).🤖 Prompt for AI Agents