Initial commit.
This commit is contained in:
commit
bf7822ca90
8 changed files with 969 additions and 0 deletions
33
sqlbase7/__init__.py
Normal file
33
sqlbase7/__init__.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# PySQLBase7 -- SQLAlchemy driver/dialect for Centura SQLBase v7
|
||||
# Copyright © 2010 Lance Edgar
|
||||
#
|
||||
# This file is part of PySQLBase7.
|
||||
#
|
||||
# PySQLBase7 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PySQLBase7 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PySQLBase7. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
|
||||
from sqlbase7 import base
|
||||
from sqlbase7 import pyodbc
|
||||
|
||||
from sqlbase7._version import __version__
|
||||
|
||||
|
||||
# default dialect
|
||||
base.dialect = pyodbc.dialect
|
26
sqlbase7/_version.py
Normal file
26
sqlbase7/_version.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# PySQLBase7 -- SQLAlchemy driver/dialect for Centura SQLBase v7
|
||||
# Copyright © 2010 Lance Edgar
|
||||
#
|
||||
# This file is part of PySQLBase7.
|
||||
#
|
||||
# PySQLBase7 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PySQLBase7 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PySQLBase7. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
|
||||
__version__ = '0.1a1'
|
85
sqlbase7/base.py
Normal file
85
sqlbase7/base.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# PySQLBase7 -- SQLAlchemy driver/dialect for Centura SQLBase v7
|
||||
# Copyright © 2010 Lance Edgar
|
||||
#
|
||||
# This file is part of PySQLBase7.
|
||||
#
|
||||
# PySQLBase7 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PySQLBase7 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PySQLBase7. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
|
||||
from sqlalchemy.engine import default
|
||||
from sqlalchemy import types
|
||||
|
||||
|
||||
class SQLBase7Dialect(default.DefaultDialect):
|
||||
|
||||
name = 'sqlbase7'
|
||||
|
||||
type_map = {
|
||||
'CHAR' : types.CHAR,
|
||||
'DATE' : types.DATE,
|
||||
'DECIMAL' : types.DECIMAL,
|
||||
'FLOAT' : types.FLOAT,
|
||||
'SMALLINT' : types.SMALLINT,
|
||||
'TIME' : types.TIME,
|
||||
'TIMESTMP' : types.TIMESTAMP,
|
||||
'VARCHAR' : types.VARCHAR,
|
||||
}
|
||||
|
||||
def _check_unicode_returns(self, connection):
|
||||
return False
|
||||
|
||||
def get_table_names(self, schema=None, connection=None):
|
||||
cursor = schema.connection.cursor()
|
||||
table_names = [row.NAME for row in cursor.execute(
|
||||
"SELECT NAME FROM SYSADM.SYSTABLES WHERE REMARKS IS NOT NULL"
|
||||
)]
|
||||
cursor.close()
|
||||
return table_names
|
||||
|
||||
def get_columns(self, connection, table_name, schema=None, **kw):
|
||||
cursor = connection.connection.cursor()
|
||||
columns = []
|
||||
|
||||
for row in cursor.execute("SELECT NAME,COLTYPE,NULLS FROM SYSADM.SYSCOLUMNS WHERE TBNAME = '%s'" % table_name):
|
||||
|
||||
columns.append({
|
||||
'name' : row.NAME,
|
||||
'type' : self.type_map[row.COLTYPE],
|
||||
'nullable' : row.NULLS == 'Y',
|
||||
'default' : None,
|
||||
'autoincrement' : False,
|
||||
})
|
||||
|
||||
cursor.close()
|
||||
return columns
|
||||
|
||||
def get_primary_keys(self, connection, table_name, schema=None, **kw):
|
||||
cursor = connection.connection.cursor()
|
||||
primary_keys = [row.NAME for row in cursor.execute(
|
||||
"SELECT NAME FROM SYSADM.SYSPKCONSTRAINTS WHERE NAME = '%s' ORDER BY PKCOLSEQNUM" % table_name
|
||||
)]
|
||||
cursor.close()
|
||||
return primary_keys
|
||||
|
||||
def get_foreign_keys(self, connection, table_name, schema=None, **kw):
|
||||
return []
|
||||
|
||||
def get_indexes(self, connection, table_name, schema=None, **kw):
|
||||
return []
|
43
sqlbase7/pyodbc.py
Normal file
43
sqlbase7/pyodbc.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# PySQLBase7 -- SQLAlchemy driver/dialect for Centura SQLBase v7
|
||||
# Copyright © 2010 Lance Edgar
|
||||
#
|
||||
# This file is part of PySQLBase7.
|
||||
#
|
||||
# PySQLBase7 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PySQLBase7 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PySQLBase7. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
|
||||
from sqlalchemy.connectors.pyodbc import PyODBCConnector
|
||||
|
||||
from sqlbase7.base import SQLBase7Dialect
|
||||
|
||||
|
||||
class SQLBase7_pyodbc(PyODBCConnector, SQLBase7Dialect):
|
||||
|
||||
def create_connect_args(self, url):
|
||||
connection_string = "DRIVER={Centura SQLBase 3.5 32-bit Driver -NT & Win95};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s" % (
|
||||
url.host,
|
||||
url.database,
|
||||
url.username,
|
||||
url.password,
|
||||
)
|
||||
return [connection_string], {}
|
||||
|
||||
|
||||
dialect = SQLBase7_pyodbc
|
55
sqlbase7/tests/__init__.py
Normal file
55
sqlbase7/tests/__init__.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# PySQLBase7 -- SQLAlchemy driver/dialect for Centura SQLBase v7
|
||||
# Copyright © 2010 Lance Edgar
|
||||
#
|
||||
# This file is part of PySQLBase7.
|
||||
#
|
||||
# PySQLBase7 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# PySQLBase7 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PySQLBase7. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from sqlalchemy import create_engine, MetaData
|
||||
|
||||
|
||||
# NOTE: This whole project exists for the sake of accessing legacy CAM32 databases,
|
||||
# so it should come as no surprise that these tests are only expected to leverage
|
||||
# such a specific database. If you do not have a CAM32 database, or if yours
|
||||
# happens to be set up in a non-standard way, etc., then you'll need to change the
|
||||
# TestCase.setUp() method to reflect your environment.
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.engine = create_engine("sqlbase7://odbc:readonly@server1/cam32")
|
||||
|
||||
|
||||
class ConnectionTestCase(TestCase):
|
||||
|
||||
def runTest(self):
|
||||
connection = self.engine.connect()
|
||||
connection.close()
|
||||
|
||||
|
||||
class ReflectionTestCase(TestCase):
|
||||
|
||||
def runTest(self):
|
||||
metadata = MetaData(bind=self.engine, reflect=True)
|
||||
self.assert_(metadata.tables)
|
Loading…
Add table
Add a link
Reference in a new issue