Update of /cvsroot/sqlobject/SQLObject/SQLObject
In directory sc8-pr-cvs1:/tmp/cvs-serv14756/SQLObject
Modified Files:
Col.py DBConnection.py
Log Message:
Basic Sybase Support, was living in a branch for some long time. Should pass most, but not all tests
Index: Col.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** Col.py 12 Nov 2003 17:04:55 -0000 1.32
--- Col.py 4 Dec 2003 16:36:16 -0000 1.33
***************
*** 182,188 ****
return ''
! def _firebirdType(self):
return self._sqlType()
def mysqlCreateSQL(self):
--- 182,190 ----
return ''
! def _sybaseType(self):
return self._sqlType()
+ def _firebirdType(self):
+ return self._sqlType()
def mysqlCreateSQL(self):
***************
*** 195,198 ****
--- 197,203 ----
return ' '.join([self.dbName, self._sqliteType()] + self._extraSQL())
+ def sybaseCreateSQL(self):
+ return ' '.join([self.dbName, self._sybaseType()] + self._extraSQL())
+
def firebirdCreateSQL(self):
# Ian Sparks pointed out that fb is picky about the order
***************
*** 374,377 ****
--- 379,385 ----
return self._postgresType()
+ def _sybaseType(self):
+ return self._postgresType()
+
def _firebirdType(self):
return self._postgresType()
***************
*** 391,396 ****
--- 399,424 ----
return 'TIMESTAMP'
+ def _sybaseType(self):
+ return self._postgresType()
+
class DateTimeCol(Col):
baseClass = SODateTimeCol
+
+ class SODateCol(SOCol):
+
+ # 3-03 @@: provide constraints; right now we let the database
+ # do any parsing and checking. And DATE and TIME?
+
+ def _mysqlType(self):
+ return 'DATE'
+
+ def _postgresType(self):
+ return 'DATE'
+
+ def _sybaseType(self):
+ return self._postgresType()
+
+ class DateCol(Col):
+ baseClass = SODateCol
class SODecimalCol(SOCol):
Index: DBConnection.py
===================================================================
RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/DBConnection.py,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** DBConnection.py 12 Nov 2003 17:06:34 -0000 1.55
--- DBConnection.py 4 Dec 2003 16:36:16 -0000 1.56
***************
*** 24,32 ****
sqlite = None
kinterbasdb = None
warnings.filterwarnings("ignore", "DB-API extension cursor.lastrowid used")
__all__ = ['MySQLConnection', 'PostgresConnection', 'SQLiteConnection',
! 'DBMConnection', 'FirebirdConnection']
_connections = {}
--- 24,33 ----
sqlite = None
kinterbasdb = None
+ Sybase = None
warnings.filterwarnings("ignore", "DB-API extension cursor.lastrowid used")
__all__ = ['MySQLConnection', 'PostgresConnection', 'SQLiteConnection',
! 'DBMConnection', 'FirebirdConnection', 'SybaseConnection']
_connections = {}
***************
*** 431,434 ****
--- 432,439 ----
self._dbConnection.releaseConnection(self._connection)
+ ########################################
+ ## MySQL connection
+ ########################################
+
class MySQLConnection(DBAPI):
***************
*** 528,531 ****
--- 533,539 ----
return Col.Col, {}
+ ########################################
+ ## Postgres connection
+ ########################################
class PostgresConnection(DBAPI):
***************
*** 683,686 ****
--- 691,698 ----
+ ########################################
+ ## SQLite connection
+ ########################################
+
class SQLiteConnection(DBAPI):
***************
*** 745,748 ****
--- 757,870 ----
########################################
+ ## Sybase connection
+ ########################################
+
+ class SybaseConnection(DBAPI):
+
+ def __init__(self, db, user, passwd='', host='localhost',
+ autoCommit=0, **kw):
+ global Sybase
+ if Sybase is None:
+ import Sybase
+ from Sybase import NumericType
+ from Converters import registerConverter, IntConverter
+ registerConverter(NumericType, IntConverter)
+ if not autoCommit and not kw.has_key('pool'):
+ # Pooling doesn't work with transactions...
+ kw['pool'] = 0
+ self.autoCommit=autoCommit
+ self.host = host
+ self.db = db
+ self.user = user
+ self.passwd = passwd
+ DBAPI.__init__(self, **kw)
+
+ def insert_id(self, conn):
+ """
+ Sybase adapter/cursor does not support the
+ insert_id method.
+ """
+ c = conn.cursor()
+ c.execute('SELECT @@IDENTITY')
+ return c.fetchone()[0]
+
+ def makeConnection(self):
+ return Sybase.connect(self.host, self.user, self.passwd,
+ database=self.db, auto_commit=self.autoCommit)
+
+ def _queryInsertID(self, conn, table, idName, names, values):
+ c = conn.cursor()
+ q = self._insertSQL(table, names, values)
+ if self.debug:
+ print 'QueryIns: %s' % q
+ c.execute(q)
+ return self.insert_id(conn)
+
+ def _queryAddLimitOffset(self, query, start, end):
+ if not start:
+ return "%s LIMIT %i" % (query, end)
+ if not end:
+ return "%s LIMIT %i, -1" % (query, start)
+ return "%s LIMIT %i, %i" % (query, start, end-start)
+
+ def createColumn(self, soClass, col):
+ return col.sybaseCreateSQL()
+
+ def createIDColumn(self, soClass):
+ #return '%s INT PRIMARY KEY AUTO_INCREMENT' % soClass._idName
+ return '%s NUMERIC(18,0) IDENTITY' % soClass._idName
+
+ def joinSQLType(self, join):
+ return 'NUMERIC(18,0) NOT NULL' #INT NOT NULL'
+
+ SHOW_TABLES="SELECT name FROM sysobjects WHERE type='U'"
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll(self.SHOW_TABLES):
+ if table.lower() == tableName.lower():
+ return True
+ return False
+
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD COLUMN %s' %
+ (tableName,
+ column.sybaseCreateSQL()))
+
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+
+ SHOW_COLUMNS=("select 'column' = COL_NAME(id, colid) "
+ "from syscolumns where id = OBJECT_ID(%s)")
+ def columnsFromSchema(self, tableName, soClass):
+ colData = self.queryAll(self.SHOW_COLUMNS
+ % tableName)
+ results = []
+ for field, t, nullAllowed, key, default, extra in colData:
+ if field == 'id':
+ continue
+ colClass, kw = self.guessClass(t)
+ kw['name'] = soClass._style.dbColumnToPythonAttr(field)
+ kw['notNone'] = not nullAllowed
+ kw['default'] = default
+ # @@ skip key...
+ # @@ skip extra...
+ results.append(colClass(**kw))
+ return results
+
+ def guessClass(self, t):
+ if t.startswith('int'):
+ return Col.IntCol, {}
+ elif t.startswith('varchar'):
+ return Col.StringCol, {'length': int(t[8:-1])}
+ elif t.startswith('char'):
+ return Col.StringCol, {'length': int(t[5:-1]),
+ 'varchar': False}
+ elif t.startswith('datetime'):
+ return Col.DateTimeCol, {}
+ else:
+ return Col.Col, {}
+
+ ########################################
## Firebird connection
########################################
***************
*** 1019,1022 ****
--- 1141,1148 ----
results.append((id,))
return results
+
+ ########################################
+ ## DBM connection
+ ########################################
class DBMConnection(FileConnection):
|