Skip to content

Commit

Permalink
Fix DDL rendered for #temp tables
Browse files Browse the repository at this point in the history
Fixes: #1
  • Loading branch information
gordthompson committed May 20, 2020
1 parent 9a872c3 commit 6d1f56b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Then, in your Python app, you can connect to the database via::
For other ways of connecting see the `Getting Connected`_ page in the Wiki.

.. _ODBC DSN (Data Source Name): https://support.microsoft.com/en-ca/help/966849/what-is-a-dsn-data-source-name
.. _Getting Connected: https://github.com/sqlalchemy/sqlalchemy-sybase/wiki/Getting-Connected
.. _Getting Connected: https://github.com/gordthompson/sqlalchemy-sybase/wiki/Getting-Connected

The SQLAlchemy Project
======================
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_sybase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .base import VARBINARY
from .base import VARCHAR

__version__ = "1.0.0"
__version__ = "1.0.1"

# default (and only) dialect
base.dialect = dialect = pyodbc.dialect
Expand Down
10 changes: 10 additions & 0 deletions sqlalchemy_sybase/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,18 @@ def visit_drop_index(self, drop):


class SybaseIdentifierPreparer(compiler.IdentifierPreparer):
# override LEGAL_CHARACTERS to add `#` for issue #1
legal_characters = re.compile(r"^[A-Z0-9_$#]+$", re.I)
reserved_words = RESERVED_WORDS

def __init__(self, dialect):
super(SybaseIdentifierPreparer, self).__init__(
dialect,
initial_quote="[",
final_quote="]",
quote_case_sensitive_collations=False,
)


class SybaseDialect(default.DefaultDialect):
name = "sybase"
Expand Down
26 changes: 24 additions & 2 deletions test/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from sqlalchemy import extract
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.future import select as future_select
from sqlalchemy.testing.suite import *
from sqlalchemy.testing.suite import (
ComponentReflectionTest as _ComponentReflectionTest,
Expand All @@ -25,7 +25,6 @@
from sqlalchemy.testing.suite import InsertBehaviorTest as _InsertBehaviorTest
from sqlalchemy.testing.suite import LastrowidTest as _LastrowidTest
from sqlalchemy.testing.suite import LimitOffsetTest as _LimitOffsetTest
from sqlalchemy.testing.suite import StringTest as _StringTest

import sqlalchemy_sybase as sybase

Expand Down Expand Up @@ -231,3 +230,26 @@ def test_delete_extra_froms_alias(self):
q, "DELETE FROM a1 FROM t1 AS a1, t2 WHERE a1.c1 = t2.c1"
)
self.assert_compile(sql.delete(a1), "DELETE FROM t1 AS a1")


class TempTableDDLTest(fixtures.TablesTest):
__backend__ = True

@classmethod
def define_tables(cls, metadata):
pass

@testing.provide_metadata
def test_temp_table(self, connection):
table_name = "#tmp"
t = Table(
table_name,
self.metadata,
Column("id", Integer, primary_key=True),
Column("txt", String(50)),
)
t.create(connection)
connection.execute(t.insert({"txt": "temp table test"}))
result = connection.scalar(future_select(t.c.id))
eq_(result, 1)
connection.execute(text(f"DROP TABLE {table_name}"))

0 comments on commit 6d1f56b

Please sign in to comment.