-
Notifications
You must be signed in to change notification settings - Fork 205
fix(sqlalchemy): add literal_processor to TIMESTAMP type #609
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import datetime | ||
| import re | ||
| from collections.abc import Iterator | ||
| from typing import Any | ||
|
|
@@ -81,6 +82,17 @@ def __init__(self, precision=None, timezone=False): | |
| super(TIMESTAMP, self).__init__(timezone=timezone) | ||
| self.precision = precision | ||
|
|
||
| def literal_processor(self, dialect): | ||
| def process(value): | ||
| if isinstance(value, datetime.datetime): | ||
| ts = value.strftime("%Y-%m-%d %H:%M:%S") | ||
|
Member
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. did you intentionally drop the zone? A zone-aware value would now be treated with session zone in Trino side. Maybe see |
||
| if value.microsecond: | ||
| ts += f".{value.microsecond // 1000:03d}" | ||
|
Member
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. truncates precision. equality predicates may no longer match. Also |
||
| return f"TIMESTAMP '{ts}'" | ||
| return str(value) | ||
|
Member
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. sql injection I think with something like
Member
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. also correctness issues in case of syntax errors: |
||
|
|
||
| return process | ||
|
|
||
|
|
||
| class JSON(TypeDecorator): | ||
| impl = JSON | ||
|
|
||
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.
add more tests: