Skip to content

Commit

Permalink
Fix missing compiler function for ALPHANUM (#214)
Browse files Browse the repository at this point in the history
Closes #213
  • Loading branch information
kasium authored Jan 31, 2024
1 parent 0fe3577 commit 92e37b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Features
- Support ``InvalidObjectNameError`` in ``sqlalchemy_hana.errors``
- Add ``convert_dbapi_error`` to ``sqlalchemy_hana.errors``

Bugfixes
~~~~~~~~
- Fixed an issue causing the usage of ALPHANUM to result in an AttributeError

1.2.0
-----

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ disable = [
]

[tool.pylint.basic]
good-names = ["visit_TINYINT", "visit_SMALLDECIMAL", "visit_SECONDDATE"]
good-names = ["visit_TINYINT", "visit_SMALLDECIMAL", "visit_SECONDDATE", "visit_ALPHANUM"]

[tool.mypy]
# formatting
Expand Down
4 changes: 4 additions & 0 deletions sqlalchemy_hana/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ def visit_SECONDDATE(self, type_: types.TypeEngine[Any], **kw: Any) -> str:
# SAP HANA special type
return "SECONDDATE"

def visit_ALPHANUM(self, type_: types.TypeEngine[Any], **kw: Any) -> str:
# SAP HANA special type
return self._render_string_type(type_, "ALPHANUM")

def visit_string(self, type_: types.TypeEngine[Any], **kw: Any) -> str:
# Normally string renders as VARCHAR, but we want NVARCHAR
return self.visit_NVARCHAR(type_, **kw)
Expand Down
14 changes: 13 additions & 1 deletion test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import sqlalchemy
import sqlalchemy.testing.suite.test_types
from sqlalchemy import inspect, testing, types
from sqlalchemy.testing.fixtures import TablesTest
from sqlalchemy.schema import CreateTable
from sqlalchemy.testing.fixtures import TablesTest, TestBase
from sqlalchemy.testing.schema import Column, Table
from sqlalchemy.testing.suite.test_types import _DateFixture

Expand Down Expand Up @@ -208,3 +209,14 @@ def reflected_column_type(self):
class NCLOBTest(_TypeBaseTest):
column_type = hana_types.NCLOB()
data = "some test text"


class AlphanumTest(TestBase):
# no real test possible because ALPHANUM is not supported in SAP HANA Cloud

def test_compile(self, connection, metadata) -> None:
mytab = Table("mytab", metadata, Column("mycol", hana_types.ALPHANUM(10)))
assert (
str(CreateTable(mytab).compile(connection))
== "\nCREATE TABLE mytab (\n\tmycol ALPHANUM(10)\n)\n\n"
)

0 comments on commit 92e37b4

Please sign in to comment.