[Zope-CVS] CVS: Products/Ape/lib/apelib/sql - ingres.py:1.1
Shane Hathaway
shane at zope.com
Wed Jul 21 03:06:21 EDT 2004
Update of /cvs-repository/Products/Ape/lib/apelib/sql
In directory cvs.zope.org:/tmp/cvs-serv8351/lib/apelib/sql
Added Files:
ingres.py
Log Message:
Added an Ingres database driver contributed by Computer Associates.
=== Added File Products/Ape/lib/apelib/sql/ingres.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Ingres-specific database connection.
$Id: ingres.py,v 1.1 2004/07/21 07:06:20 shane Exp $
"""
from apelib.sql.dbapi import AbstractSQLConnection
class IngresConnection (AbstractSQLConnection):
column_type_translations = {
'long': 'bigint',
'string': 'varchar(255)',
'datetime': 'time',
'boolean': 'tinyint',
}
column_name_translations = {
'oid': 'objoid',
}
def exists(self, name, type_name):
"""Returns true if the specified database object exists.
type_name is 'table' or 'sequence'
"""
table_name = self.prefix + name
if type_name == 'table':
sql = ('SELECT table_name FROM iitables '
'WHERE table_name = :name')
elif type_name == 'sequence':
sql = ("SELECT seq_name FROM ii_sequences "
"WHERE seq_name = :name")
else:
raise ValueError(type_name)
rows = self.execute(sql, {'name': table_name.lower()}, fetch=1)
return len(rows)
def list_table_names(self):
"""Returns a list of existing table names.
"""
sql = 'SELECT table_name FROM ii_tables'
rows = self.execute(sql, {}, fetch=1)
res = []
for (name,) in rows:
if not self.prefix or name.startswith(self.prefix):
res.append(name[len(self.prefix):])
return res
def create_sequence(self, name, start=1):
"""Creates a sequence.
"""
sql = "CREATE SEQUENCE %s START WITH %d" % (
self.prefix + name, start)
self.execute(sql)
def reset_sequence(self, name, start=1):
"""Resets a sequence.
"""
sql = "ALTER SEQUENCE '%s' RESTART WITH %d" % (
self.prefix + name, start)
self.execute(sql)
def increment(self, name):
"""Increments a sequence.
"""
sql = "SELECT NEXT VALUE FOR '%s'" % (self.prefix + name)
rows = self.execute(sql, fetch=1)
return rows[0][0]
More information about the Zope-CVS
mailing list