Initial commit.
This commit is contained in:
commit
bf7822ca90
8 changed files with 969 additions and 0 deletions
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 []
|
Loading…
Add table
Add a link
Reference in a new issue