sqlobject-cvs Mailing List for SQLObject (Page 179)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
| 2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
| 2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
| 2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
| 2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
| 2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
| 2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
| 2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
| 2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
| 2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
| 2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
| 2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
| 2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
| 2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
| 2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
| 2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
| 2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(2) |
Dec
(2) |
|
From: <sub...@co...> - 2004-06-14 12:51:02
|
Author: ahmedmo
Date: 2004-06-14 04:48:23 -0400 (Mon, 14 Jun 2004)
New Revision: 145
Removed:
trunk/SQLObject/col.py
Log:
Removed file/folder
Deleted: trunk/SQLObject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/col.py 2004-06-14 08:47:01 UTC (rev 144)
+++ trunk/SQLObject/col.py 2004-06-14 08:48:23 UTC (rev 145)
@@ -1,608 +0,0 @@
-"""
-Col
-"""
-
-import sqlbuilder
-import re
-# Sadly the name "constraints" conflicts with many of the function
-# arguments in this module, so we rename it:
-import constraints as consts
-from include import validators
-
-NoDefault =3D sqlbuilder.NoDefault
-True, False =3D 1=3D=3D1, 0=3D=3D1
- =20
-
-########################################
-## Columns
-########################################
-
-# Col is essentially a column definition, it doesn't have
-# much logic to it.
-class SOCol(object):
-
- def __init__(self,
- name,
- soClass,
- dbName=3DNone,
- default=3DNoDefault,
- foreignKey=3DNone,
- alternateID=3DFalse,
- alternateMethodName=3DNone,
- constraints=3DNone,
- notNull=3DNoDefault,
- notNone=3DNoDefault,
- unique=3DNoDefault,
- sqlType=3DNone,
- columnDef=3DNone,
- validator=3DNone,
- immutable=3DFalse,
- cascade=3DNone,
- lazy=3DFalse,
- noCache=3DFalse):
-
- # This isn't strictly true, since we *could* use backquotes or
- # " or something (database-specific) around column names, but
- # why would anyone *want* to use a name like that?
- # @@: I suppose we could actually add backquotes to the
- # dbName if we needed to...
- assert sqlbuilder.sqlIdentifier(name), 'Name must be SQL-safe (l=
etters, numbers, underscores): %s' \
- % repr(name)
- assert name !=3D 'id', 'The column name "id" is reserved for SQL=
Object use (and is implicitly created).'
- assert name, "You must provide a name for all columns"
-
- self.columnDef =3D columnDef
-
- self.immutable =3D immutable
-
- # cascade can be one of:
- # None: no constraint is generated
- # True: a CASCADE constraint is generated
- # False: a RESTRICT constraint is generated
- self.cascade =3D cascade
-
- if type(constraints) not in (type([]), type(())):
- constraints =3D [constraints]
- self.constraints =3D self.autoConstraints() + constraints
-
- self.notNone =3D False
- if notNull is not NoDefault:
- self.notNone =3D notNull
- assert notNone is NoDefault or \
- (not notNone) =3D=3D (not notNull), \
- "The notNull and notNone arguments are aliases, and m=
ust not conflict. You gave notNull=3D%r, notNone=3D%r" % (notNull, notNo=
ne)
- elif notNone is not NoDefault:
- self.notNone =3D notNone
- if self.notNone:
- self.constraints =3D [consts.notNull] + self.constraints
-
- self.name =3D name
- self.soClass =3D None
- self._default =3D default
- self.customSQLType =3D sqlType
-
- self.foreignKey =3D foreignKey
- if self.foreignKey:
- #assert self.name.upper().endswith('ID'), "All foreign key c=
olumns must end with 'ID' (%s)" % repr(self.name)
- if not self.name.upper().endswith('ID'):
- self.foreignName =3D self.name
- self.name =3D self.name + "ID"
- else:
- self.foreignName =3D self.name[:-2]
- else:
- self.foreignName =3D None
-
- # if they don't give us a specific database name for
- # the column, we separate the mixedCase into mixed_case
- # and assume that.
- if dbName is None:
- self.dbName =3D soClass._style.pythonAttrToDBColumn(self.nam=
e)
- else:
- self.dbName =3D dbName
-
- # alternateID means that this is a unique column that
- # can be used to identify rows
- self.alternateID =3D alternateID
- if self.alternateID and alternateMethodName is None:
- self.alternateMethodName =3D 'by' + self.name[0].capitalize(=
) + self.name[1:]
- else:
- self.alternateMethodName =3D alternateMethodName
-
- if unique is NoDefault:
- self.unique =3D alternateID
- else:
- self.unique =3D unique
-
- self.validator =3D validator
- self.noCache =3D noCache
- self.lazy =3D lazy
-
- def _set_validator(self, value):
- self._validator =3D value
- if self._validator:
- self.toPython =3D self._validator.toPython
- self.fromPython =3D self._validator.fromPython
- else:
- self.toPython =3D None
- self.fromPython =3D None
-
- def _get_validator(self):
- return self._validator
-
- validator =3D property(_get_validator, _set_validator)
-
- def autoConstraints(self):
- return []
-
- def _get_default(self):
- # A default can be a callback or a plain value,
- # here we resolve the callback
- if self._default is NoDefault:
- return NoDefault
- elif hasattr(self._default, '__sqlrepr__'):
- return self._default
- elif callable(self._default):
- return self._default()
- else:
- return self._default
- default =3D property(_get_default, None, None)
-
- def _get_joinName(self):
- assert self.name[-2:] =3D=3D 'ID'
- return self.name[:-2]
- joinName =3D property(_get_joinName, None, None)
-
- def __repr__(self):
- r =3D '<%s %s' % (self.__class__.__name__, self.name)
- if self.default is not NoDefault:
- r +=3D ' default=3D%s' % repr(self.default)
- if self.foreignKey:
- r +=3D ' connected to %s' % self.foreignKey
- if self.alternateID:
- r +=3D ' alternate ID'
- if self.notNone:
- r +=3D ' not null'
- return r + '>'
-
- def createSQL(self):
- return ' '.join([self._sqlType() + self._extraSQL()])
-
- def _extraSQL(self):
- result =3D []
- if self.notNone or self.alternateID:
- result.append('NOT NULL')
- if self.unique or self.alternateID:
- result.append('UNIQUE')
- return result
-
- def _sqlType(self):
- if self.customSQLType is None:
- raise ValueError, ("Col %s (%s) cannot be used for automatic=
"
- "schema creation (too abstract)" %
- (self.name, self.__class__))
- else:
- return self.customSQLType
-
- def _mysqlType(self):
- return self._sqlType()
-
- def _postgresType(self):
- return self._sqlType()
-
- def _sqliteType(self):
- # SQLite is naturally typeless, so as a fallback it uses
- # no type.
- try:
- return self._sqlType()
- except ValueError:
- return ''
-
- def _sybaseType(self):
- return self._sqlType()
-
- def _firebirdType(self):
- return self._sqlType()
- =20
- def _maxdbType(self):
- return self._sqlType()
-
- def mysqlCreateSQL(self):
- return ' '.join([self.dbName, self._mysqlType()] + self._extraSQ=
L())
-
- def postgresCreateSQL(self):
- return ' '.join([self.dbName, self._postgresType()] + self._extr=
aSQL())
-
- def sqliteCreateSQL(self):
- return ' '.join([self.dbName, self._sqliteType()] + self._extraS=
QL())
-
- def sybaseCreateSQL(self):
- return ' '.join([self.dbName, self._sybaseType()] + self._extraS=
QL())
-
- def firebirdCreateSQL(self):
- # Ian Sparks pointed out that fb is picky about the order
- # of the NOT NULL clause in a create statement. So, we handle
- # them differently for Enum columns.
- if not isinstance(self, SOEnumCol):
- return ' '.join([self.dbName, self._firebirdType()] + self._=
extraSQL())
- else:
- return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
-=09
- def maxdbCreateSQL(self):
- return ' '.join([self.dbName, self._maxdbType()] + self._extraSQL=
())
-
- def __get__(self, obj, type=3DNone):
- if obj is None:
- # class attribute, return the descriptor itself
- return self
- if obj.sqlmeta.obsolete:
- raise '@@: figure out the exception for a delete'
- if obj.sqlmeta.cacheColumns:
- columns =3D obj.sqlmeta._columnCache
- if columns is None:
- obj.sqlmeta.loadValues()
- try:
- return columns[name]
- except KeyError:
- return obj.sqlmeta.loadColumn(self)
- else:
- return obj.sqlmeta.loadColumn(self)
-
- def __set__(self, obj, value):
- if self.immutable:
- raise AttributeError("The column %s.%s is immutable" %
- (obj.__class__.__name__,
- self.name))
- obj.sqlmeta.setColumn(self, value)
-
- def __delete__(self, obj):
- raise AttributeError("I can't be deleted from %r" % obj)
-
-
-class Col(object):
-
- baseClass =3D SOCol
-
- def __init__(self, name=3DNone, **kw):
- kw['name'] =3D name
- kw['columnDef'] =3D self
- self.kw =3D kw
-
- def setName(self, value):
- assert self.kw['name'] is None, "You cannot change a name after =
it has already been set (from %s to %s)" % (self.kw['name'], value)
- self.kw['name'] =3D value
-
- def withClass(self, soClass):
- return self.baseClass(soClass=3DsoClass, **self.kw)
-
-class SOStringCol(SOCol):
-
- # 3-03 @@: What about BLOB?
-
- def __init__(self, **kw):
- self.length =3D popKey(kw, 'length')
- self.varchar =3D popKey(kw, 'varchar', 'auto')
- if not self.length:
- assert self.varchar =3D=3D 'auto' or not self.varchar, \
- "Without a length strings are treated as TEXT, not va=
rchar"
- self.varchar =3D False
- elif self.varchar =3D=3D 'auto':
- self.varchar =3D True
-
- SOCol.__init__(self, **kw)
-
- def autoConstraints(self):
- constraints =3D [consts.isString]
- if self.length is not None:
- constraints +=3D [consts.MaxLength(self.length)]
- return constraints
-
- def _sqlType(self):
- if not self.length:
- return 'TEXT'
- elif self.varchar:
- return 'VARCHAR(%i)' % self.length
- else:
- return 'CHAR(%i)' % self.length
-
- def _firebirdType(self):
- if not self.length:
- return 'BLOB SUB_TYPE TEXT'
- else:
- return self._sqlType()
- =20
- def _maxdbType(self):
- if not self.length:
- return 'LONG ASCII'
- else:
- return self._sqlType()
-
-class StringCol(Col):
- baseClass =3D SOStringCol
-
-class SOIntCol(SOCol):
-
- # 3-03 @@: support precision, maybe max and min directly
-
- def autoConstraints(self):
- return [consts.isInt]
-
- def _sqlType(self):
- return 'INT'
-
-class IntCol(Col):
- baseClass =3D SOIntCol
-
-class BoolValidator(validators.Validator):
-
- def fromPython(self, value, state):
- if value:
- return sqlbuilder.TRUE
- else:
- return sqlbuilder.FALSE
-
- def toPython(self, value, state):
- if not value or not int(value):
- return sqlbuilder.FALSE
- else:
- return sqlbuilder.TRUE
-
-class SOBoolCol(SOCol):
-
- def __init__(self, **kw):
- SOCol.__init__(self, **kw)
- self.validator =3D validators.All.join(BoolValidator(), self.val=
idator)
-
- def autoConstraints(self):
- return [consts.isBool]
-
- def _postgresType(self):
- return 'BOOL'
-
- def _mysqlType(self):
- return "TINYINT"
-
- def _sybaseType(self):
- return "BIT"
-
- def _firebirdType(self):
- return 'INT'
- =20
- def _maxdbType(self):
- return "BOOLEAN"
-
-class BoolCol(Col):
- baseClass =3D SOBoolCol
-
-class SOFloatCol(SOCol):
-
- # 3-03 @@: support precision (e.g., DECIMAL)
-
- def autoConstraints(self):
- return [consts.isFloat]
-
- def _sqlType(self):
- return 'FLOAT'
-
-class FloatCol(Col):
- baseClass =3D SOFloatCol
-
-class SOKeyCol(SOCol):
-
- # 3-03 @@: this should have a simplified constructor
- # Should provide foreign key information for other DBs.
-
- def _mysqlType(self):
- return 'INT'
-
- def _sqliteType(self):
- return 'INT'
-
- def _postgresType(self):
- return 'INT'
-
- def _sybaseType(self):
- return 'INT'
-
- def _firebirdType(self):
- return 'INT'
- =20
- def _maxdbType(self):
- return 'INT'
-
-class KeyCol(Col):
-
- baseClass =3D SOKeyCol
-
-class SOForeignKey(SOKeyCol):
-
- def __init__(self, **kw):
- foreignKey =3D kw['foreignKey']
- style =3D kw['soClass']._style
- if not kw.get('name'):
- kw['name'] =3D style.instanceAttrToIDAttr(style.pythonClassT=
oAttr(foreignKey))
- else:
- if not kw['name'].upper().endswith('ID'):
- kw['name'] =3D style.instanceAttrToIDAttr(kw['name'])
- SOKeyCol.__init__(self, **kw)
-
- def postgresCreateSQL(self):
- from main import findClass
- sql =3D SOKeyCol.postgresCreateSQL(self)
- if self.cascade is not None:
- other =3D findClass(self.foreignKey)
- tName =3D other._table
- idName =3D other._idName
- action =3D self.cascade and 'CASCADE' or 'RESTRICT'
- constraint =3D ('CONSTRAINT %(tName)s_exists '
- 'FOREIGN KEY(%(colName)s) '
- 'REFERENCES %(tName)s(%(idName)s) '
- 'ON DELETE %(action)s' %
- {'tName':tName,
- 'colName':self.dbName,
- 'idName':idName,
- 'action':action})
- sql =3D ', '.join([sql, constraint])
- return sql
-
- def sybaseCreateSQL(self):
- from SQLObject import findClass
- sql =3D SOKeyCol.sybaseCreateSQL(self)
- other =3D findClass(self.foreignKey)
- tName =3D other._table
- idName =3D other._idName
- reference =3D ('REFERENCES %(tName)s(%(idName)s) ' %
- {'tName':tName,
- 'idName':idName})
- sql =3D ' '.join([sql, reference])
- return sql
- =20
- def maxdbCreateSQL(self):
- from main import findClass
- other =3D findClass(self.foreignKey)
- fidName =3D self.dbName
- #I assume that foreign key name is identical to the id of the referen=
ce table =09
- sql =3D ' '.join([fidName, self._maxdbType()])
- tName =3D other._table
- idName =3D other._idName
- sql=3Dsql + ',' + '\n'=20
- sql=3Dsql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idNam=
e)
- return sql
-
-class ForeignKey(KeyCol):
-
- baseClass =3D SOForeignKey
-
- def __init__(self, foreignKey=3DNone, **kw):
- KeyCol.__init__(self, foreignKey=3DforeignKey, **kw)
-
-class SOEnumCol(SOCol):
-
- def __init__(self, **kw):
- self.enumValues =3D popKey(kw, 'enumValues', None)
- assert self.enumValues is not None, \
- 'You must provide an enumValues keyword argument'
- SOCol.__init__(self, **kw)
-
- def autoConstraints(self):
- return [consts.isString, consts.InList(self.enumValues)]
-
- def _mysqlType(self):
- return "ENUM(%s)" % ', '.join([sqlbuilder.sqlrepr(v, 'mysql') fo=
r v in self.enumValues])
-
- def _postgresType(self):
- length =3D max(map(len, self.enumValues))
- enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'postgres') for =
v in self.enumValues])
- checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
- return "VARCHAR(%i) %s" % (length, checkConstraint)
-
- def _sqliteType(self):
- return self._postgresType()
-
- def _sybaseType(self):
- return self._postgresType()
-
- def _firebirdType(self):
- length =3D max(map(len, self.enumValues))
- enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for =
v in self.enumValues])
- checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
- #NB. Return a tuple, not a string here
- return "VARCHAR(%i)" % (length), checkConstraint
-=20
- def _maxdbType(self):
- raise "Enum type is not supported"
-
-class EnumCol(Col):
- baseClass =3D SOEnumCol
-
-class SODateTimeCol(SOCol):
-
- # 3-03 @@: provide constraints; right now we let the database
- # do any parsing and checking. And DATE and TIME?
-
- def _mysqlType(self):
- return 'DATETIME'
-
- def _postgresType(self):
- return 'TIMESTAMP'
-
- def _sybaseType(self):
- return 'DATETIME'
-
- def _sqliteType(self):
- return 'TIMESTAMP'
-
- def _firebirdType(self):
- return 'TIMESTAMP'
- =20
- def _maxdbType(self):
- return 'TIMESTAMP'
-
-class DateTimeCol(Col):
- baseClass =3D 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()
-
- def _firebirdType(self):
- return 'DATE'
- =20
- def _maxdbType(self):
- return 'DATE'
-
-class DateCol(Col):
- baseClass =3D SODateCol
-
-class SODecimalCol(SOCol):
-
- def __init__(self, **kw):
- self.size =3D popKey(kw, 'size', NoDefault)
- assert self.size is not NoDefault, \
- "You must give a size argument"
- self.precision =3D popKey(kw, 'precision', NoDefault)
- assert self.precision is not NoDefault, \
- "You must give a precision argument"
- SOCol.__init__(self, **kw)
-
- def _sqlType(self):
- return 'DECIMAL(%i, %i)' % (self.size, self.precision)
-
-class DecimalCol(Col):
- baseClass =3D SODecimalCol
-
-class SOCurrencyCol(SODecimalCol):
-
- def __init__(self, **kw):
- pushKey(kw, 'size', 10)
- pushKey(kw, 'precision', 2)
- SODecimalCol.__init__(self, **kw)
-
-class CurrencyCol(DecimalCol):
- baseClass =3D SOCurrencyCol
-
-def popKey(kw, name, default=3DNone):
- if not kw.has_key(name):
- return default
- value =3D kw[name]
- del kw[name]
- return value
-
-def pushKey(kw, name, value):
- if not kw.has_key(name):
- kw[name] =3D value
-
-all =3D []
-for key, value in globals().items():
- if isinstance(value, type) and issubclass(value, Col):
- all.append(key)
-__all__ =3D all
|
|
From: <sub...@co...> - 2004-06-14 12:49:34
|
Author: ahmedmo
Date: 2004-06-14 04:47:01 -0400 (Mon, 14 Jun 2004)
New Revision: 144
Modified:
trunk/SQLObject/sqlobject/converters.py
Log:
Modified: trunk/SQLObject/sqlobject/converters.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/converters.py 2004-06-14 08:46:52 UTC (rev =
143)
+++ trunk/SQLObject/sqlobject/converters.py 2004-06-14 08:47:01 UTC (rev =
144)
@@ -92,7 +92,7 @@
if db in ('mysql', 'postgres', 'sybase'):
for orig, repl in sqlStringReplace:
value =3D value.replace(orig, repl)
- elif db in ('sqlite', 'firebird'):
+ elif db in ('sqlite', 'firebird','maxdb'):
value =3D value.replace("'", "''")
else:
assert 0, "Database %s unknown" % db
|
|
From: <sub...@co...> - 2004-06-14 12:49:28
|
Author: ahmedmo
Date: 2004-06-14 04:46:52 -0400 (Mon, 14 Jun 2004)
New Revision: 143
Modified:
trunk/SQLObject/sqlobject/__init__.py
Log:
Modified: trunk/SQLObject/sqlobject/__init__.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/__init__.py 2004-06-14 08:46:43 UTC (rev 14=
2)
+++ trunk/SQLObject/sqlobject/__init__.py 2004-06-14 08:46:52 UTC (rev 14=
3)
@@ -56,3 +56,9 @@
_sybase.builder()(*args, **kw)
=20
=20
+import maxdb
+_maxdb =3D maxdb
+del maxdb
+def MaxdbConnection(*args, **kw):
+ _warn('MaxdbConnection is deprecated; use connectionForURI("maxdb://=
...") or "from sqlobject.maxdb import builder; MaxdbConnection =3D builde=
r()"')
+ _maxdb.builder()(*args, **kw)
\ No newline at end of file
|
|
From: <sub...@co...> - 2004-06-14 12:49:16
|
Author: ahmedmo
Date: 2004-06-14 04:46:43 -0400 (Mon, 14 Jun 2004)
New Revision: 142
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Modified: trunk/SQLObject/sqlobject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/col.py 2004-06-14 08:35:02 UTC (rev 141)
+++ trunk/SQLObject/sqlobject/col.py 2004-06-14 08:46:43 UTC (rev 142)
@@ -202,6 +202,9 @@
=20
def _firebirdType(self):
return self._sqlType()
+ =20
+ def _maxdbType(self):
+ return self._sqlType()
=20
def mysqlCreateSQL(self):
return ' '.join([self.dbName, self._mysqlType()] + self._extraSQ=
L())
@@ -221,8 +224,11 @@
# them differently for Enum columns.
if not isinstance(self, SOEnumCol):
return ' '.join([self.dbName, self._firebirdType()] + self._=
extraSQL())
- else:
- return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
+ else:
+ return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
+=09
+ def maxdbCreateSQL(self):
+ return ' '.join([self.dbName, self._maxdbType()] + self._extraSQL=
())
=20
def __get__(self, obj, type=3DNone):
if obj is None:
@@ -303,6 +309,12 @@
return 'BLOB SUB_TYPE TEXT'
else:
return self._sqlType()
+ =20
+ def _maxdbType(self):
+ if not self.length:
+ return 'LONG ASCII'
+ else:
+ return self._sqlType()
=20
class StringCol(Col):
baseClass =3D SOStringCol
@@ -354,6 +366,9 @@
=20
def _firebirdType(self):
return 'INT'
+ =20
+ def _maxdbType(self):
+ return "BOOLEAN"
=20
class BoolCol(Col):
baseClass =3D SOBoolCol
@@ -390,6 +405,9 @@
=20
def _firebirdType(self):
return 'INT'
+ =20
+ def _maxdbType(self):
+ return 'INT'
=20
class KeyCol(Col):
=20
@@ -437,6 +455,18 @@
'idName':idName})
sql =3D ' '.join([sql, reference])
return sql
+ =20
+ def maxdbCreateSQL(self):
+ from main import findClass
+ other =3D findClass(self.foreignKey)
+ fidName =3D self.dbName
+ #I assume that foreign key name is identical to the id of the referen=
ce table =09
+ sql =3D ' '.join([fidName, self._maxdbType()])
+ tName =3D other._table
+ idName =3D other._idName
+ sql=3Dsql + ',' + '\n'=20
+ sql=3Dsql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idNam=
e)
+ return sql
=20
class ForeignKey(KeyCol):
=20
@@ -475,8 +505,11 @@
length =3D max(map(len, self.enumValues))
enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for =
v in self.enumValues])
checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
- #NB. Return a tuple, not a string here
- return "VARCHAR(%i)" % (length), checkConstraint
+ #NB. Return a tuple, not a string here
+ return "VARCHAR(%i)" % (length), checkConstraint
+=20
+ def _maxdbType(self):
+ raise "Enum type is not supported"
=20
class EnumCol(Col):
baseClass =3D SOEnumCol
@@ -497,10 +530,13 @@
=20
def _sqliteType(self):
return 'TIMESTAMP'
-
+
def _firebirdType(self):
- return 'TIMESTAMP'
-
+ return 'TIMESTAMP'
+ =20
+ def _maxdbType(self):
+ return 'TIMESTAMP'
+
class DateTimeCol(Col):
baseClass =3D SODateTimeCol
=20
@@ -517,9 +553,12 @@
=20
def _sybaseType(self):
return self._postgresType()
-
+
def _firebirdType(self):
- return 'DATE'
+ return 'DATE'
+ =20
+ def _maxdbType(self):
+ return 'DATE'
=20
class DateCol(Col):
baseClass =3D SODateCol
|
|
From: <sub...@co...> - 2004-06-14 12:37:37
|
Author: ahmedmo
Date: 2004-06-14 04:35:02 -0400 (Mon, 14 Jun 2004)
New Revision: 141
Modified:
trunk/SQLObject/converters.py
Log:
Modified: trunk/SQLObject/converters.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/converters.py 2004-06-14 08:34:16 UTC (rev 140)
+++ trunk/SQLObject/converters.py 2004-06-14 08:35:02 UTC (rev 141)
@@ -83,7 +83,7 @@
# lookup on klasses dict
return self.klass.get(value.__class__, default)
return self.basic.get(type(value), default)
-
+ =20
converters =3D ConverterRegistry()
registerConverter =3D converters.registerConverter
lookupConverter =3D converters.lookupConverter
|
|
From: <sub...@co...> - 2004-06-14 12:36:50
|
Author: ahmedmo
Date: 2004-06-14 04:34:16 -0400 (Mon, 14 Jun 2004)
New Revision: 140
Modified:
trunk/SQLObject/col.py
Log:
Modified: trunk/SQLObject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/col.py 2004-06-14 08:07:50 UTC (rev 139)
+++ trunk/SQLObject/col.py 2004-06-14 08:34:16 UTC (rev 140)
@@ -202,10 +202,10 @@
=20
def _firebirdType(self):
return self._sqlType()
- =20
+ =20
def _maxdbType(self):
- return self._sqlType() =20
- =20
+ return self._sqlType()
+
def mysqlCreateSQL(self):
return ' '.join([self.dbName, self._mysqlType()] + self._extraSQ=
L())
=20
@@ -226,9 +226,9 @@
return ' '.join([self.dbName, self._firebirdType()] + self._=
extraSQL())
else:
return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
- =20
+=09
def maxdbCreateSQL(self):
- return ' '.join([self.dbName, self._maxdbType()] + self._extraSQ=
L())
+ return ' '.join([self.dbName, self._maxdbType()] + self._extraSQL=
())
=20
def __get__(self, obj, type=3DNone):
if obj is None:
@@ -311,10 +311,10 @@
return self._sqlType()
=20
def _maxdbType(self):
- if not self.length:
- return 'LONG ASCII'
- else:
- return self._sqlType()
+ if not self.length:
+ return 'LONG ASCII'
+ else:
+ return self._sqlType()
=20
class StringCol(Col):
baseClass =3D SOStringCol
@@ -328,9 +328,6 @@
=20
def _sqlType(self):
return 'INT'
- =20
- def _maxdbType(self):
- return 'INT'
=20
class IntCol(Col):
baseClass =3D SOIntCol
@@ -369,9 +366,9 @@
=20
def _firebirdType(self):
return 'INT'
- =20
- def _maxdbType(self):
- return "BOOLEAN"
+ =20
+ def _maxdbType(self):
+ return "BOOLEAN"
=20
class BoolCol(Col):
baseClass =3D SOBoolCol
@@ -460,16 +457,16 @@
return sql
=20
def maxdbCreateSQL(self):
- from main import findClass
- other =3D findClass(self.foreignKey)
- fidName =3D self.dbName
- #I assume that foreign key name is identical to the id of the referenc=
e table =09
- sql =3D ' '.join([fidName, self._maxdbType()])
- tName =3D other._table
- idName =3D other._idName
- sql=3Dsql + ',' + '\n'=20
- sql=3Dsql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idName=
)
- return sql
+ from main import findClass
+ other =3D findClass(self.foreignKey)
+ fidName =3D self.dbName
+ #I assume that foreign key name is identical to the id of the referen=
ce table =09
+ sql =3D ' '.join([fidName, self._maxdbType()])
+ tName =3D other._table
+ idName =3D other._idName
+ sql=3Dsql + ',' + '\n'=20
+ sql=3Dsql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idNam=
e)
+ return sql
=20
class ForeignKey(KeyCol):
=20
@@ -510,10 +507,9 @@
checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
#NB. Return a tuple, not a string here
return "VARCHAR(%i)" % (length), checkConstraint
- =20
+=20
def _maxdbType(self):
raise "Enum type is not supported"
- =20
=20
class EnumCol(Col):
baseClass =3D SOEnumCol
@@ -537,9 +533,9 @@
=20
def _firebirdType(self):
return 'TIMESTAMP'
- =20
- def _maxdbType(self):
- return 'TIMESTAMP'
+ =20
+ def _maxdbType(self):
+ return 'TIMESTAMP'
=20
class DateTimeCol(Col):
baseClass =3D SODateTimeCol
|
|
From: <sub...@co...> - 2004-06-14 12:10:24
|
Author: ahmedmo
Date: 2004-06-14 04:07:50 -0400 (Mon, 14 Jun 2004)
New Revision: 139
Modified:
trunk/SQLObject/col.py
Log:
Modified: trunk/SQLObject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/col.py 2004-06-14 08:03:14 UTC (rev 138)
+++ trunk/SQLObject/col.py 2004-06-14 08:07:50 UTC (rev 139)
@@ -202,7 +202,7 @@
=20
def _firebirdType(self):
return self._sqlType()
- =20
+ =20
def _maxdbType(self):
return self._sqlType() =20
=20
|
|
From: <sub...@co...> - 2004-06-14 12:05:48
|
Author: ahmedmo
Date: 2004-06-14 04:03:14 -0400 (Mon, 14 Jun 2004)
New Revision: 138
Added:
trunk/SQLObject/sqlobject/maxdb/__init__.py
trunk/SQLObject/sqlobject/maxdb/__init__.pyc
trunk/SQLObject/sqlobject/maxdb/maxdbconnection.py
trunk/SQLObject/sqlobject/maxdb/maxdbconnection.pyc
Log:
Added: trunk/SQLObject/sqlobject/maxdb/__init__.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/maxdb/__init__.py 2004-06-14 08:02:26 UTC (=
rev 137)
+++ trunk/SQLObject/sqlobject/maxdb/__init__.py 2004-06-14 08:03:14 UTC (=
rev 138)
@@ -0,0 +1,14 @@
+from sqlobject.dbconnection import registerConnection
+
+def builder():
+ import maxdbconnection
+ return maxdbconnection.MaxdbConnection
+
+def isSupported():
+ try:
+ import sapdb
+ except ImportError:
+ return False
+ return False
+
+registerConnection(['maxdb','sapdb'],builder, isSupported)
Added: trunk/SQLObject/sqlobject/maxdb/__init__.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/sqlobject/maxdb/__init__.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/SQLObject/sqlobject/maxdb/maxdbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/maxdb/maxdbconnection.py 2004-06-14 08:02:2=
6 UTC (rev 137)
+++ trunk/SQLObject/sqlobject/maxdb/maxdbconnection.py 2004-06-14 08:03:1=
4 UTC (rev 138)
@@ -0,0 +1,276 @@
+"""
+Contributed by Edigram SAS,Paris=20
+Ahmed MOHAMED ALI <ahm...@ya...> 27 April 2004
+This program 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.
+
+connection creation sample=20
+__connection__ =3D DBConnection.maxdbConnection(
+ host=3Dhostname, database=3Ddbname,
+ user=3Duser_name, password=3Duser_password,autoCommit=3D1,debug=3D1)
+"""
+from sqlobject.dbconnection import DBAPI
+from sqlobject import col
+dbapi =3D None
+
+
+
+class maxdbException(Exception):
+ def __init__(self, value):
+ self.value =3D value
+ def __str__(self):
+ return repr(self.value)
+=09
+class LowerBoundOfSliceIsNotSupported(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'')
+=09
+
+class IncorrectIDStyleError(maxdbException) :
+ def __init__(self,value):
+ maxdbException.__init__(self,'This primary key name is not in the exp=
ected style,please rename the column to %s or switch to another style'%(v=
alue))
+
+class StyleMismatchError(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'The name %s is only permitted for primar=
y key,change the column name or switch to another style'%value)
+
+
+class PrimaryKeyNotFounded(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,"No primary key was defined on table %s"%=
(value))
+
+ =09
+SAPDBMAX_ID_LENGTH=3D32 =20
+ =09
+class MaxdbConnection(DBAPI):
+
+ =20
+ supportTransactions =3D True
+ dbName =3D 'maxdb'
+ schemes =3D [dbName]
+ =20
+ def __init__ (self, user, password, database, host =3D '',autoCommit=3D=
1,sqlmode=3D'internal',isolation=3DNone,timeout=3DNone, **kw):
+ global dbapi
+ if dbapi is None:
+ from sapdb import dbapi
+ self.autoCommit =3D autoCommit
+ self.user =3D user
+ self.password =3D password
+ self.database =3D database
+ self.host =3D host
+ self.sqlmode =3D sqlmode
+ self.isolation =3D isolation
+ self.timeout =3D timeout
+ =20
+ DBAPI.__init__(self, **kw)
+ =20
+ def connectionFromURI(cls, uri):
+ auth, password, host, path, args =3D cls._parseURI(uri)
+ path =3D path.replace('/', os.path.sep)
+ return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **args)
+ connectionFromURI =3D classmethod(connectionFromURI)
+=09
+ =09
+ def _getConfigParams(self,sqlmode,auto):
+ autocommit=3D'off'
+ if auto:autocommit=3D'on'
+ opt=3D{}
+ opt["autocommit"]=3Dautocommit
+ opt["sqlmode"]=3Dsqlmode
+ if self.isolation:
+ opt["isolation"]=3Dself.isolation
+ if self.timeout :
+ opt["timeout"]=3Dself.timeout
+ =09
+ return opt
+ =09
+ def _setAutoCommit(self, conn, auto):
+ conn.close()
+ conn.__init__(self.user, self.password, self.database, self.host,**sel=
f._getConfigParams(self.sqlmode,auto))
+ =09
+ =20
+=09
+ =20
+ def createSequenceName(self,table):
+ """ sequence name are builded with the concatenation of the table name=
with '_SEQ' word
+ we truncate the name of the sequence_name because
+ sapdb identifier cannot exceed 32 characters
+ so that the name of the sequence does not exceed 32 characters
+ """
+ return '%s_SEQ'%(table[:SAPDBMAX_ID_LENGTH -4])
+=09
+ def makeConnection(self):
+ conn =3D dbapi.Connection(self.user, self.password, self.database, se=
lf.host,**self._getConfigParams(self.sqlmode,self.autoCommit) )
+ return conn
+=09
+ def _queryInsertID(self, conn, table, idName, id, names, values):
+ c =3D conn.cursor()
+ if id is None:
+ c.execute('SELECT %s.NEXTVAL FROM DUAL' % (self.createSequenceName(ta=
ble)))
+ id =3D c.fetchone()[0]
+ names =3D [idName] + names
+ values =3D [id] + values
+ q =3D self._insertSQL(table, names, values)
+ if self.debug:
+ self.printDebug(conn, q, 'QueryIns')
+ c.execute(q)
+ if self.debugOutput:
+ self.printDebug(conn, id, 'QueryIns', 'result')
+ return id
+=09
+ def sqlAddLimit(self,query,limit):
+ sql =3D query
+ sql =3D sql.replace("SELECT","SELECT ROWNO, ")
+ if sql.find('WHERE') !=3D -1:
+ sql =3D sql + ' AND ' + limit
+ else:=09
+ sql =3D sql + 'WHERE ' + limit
+
+ return sql
+ =09
+ def _queryAddLimitOffset(self, query, start, end):
+ if start: raise LowerBoundOfSliceIsNotSupported
+ limit =3D ' ROWNO <=3D %d ' % (end)
+ return self.sqlAddLimit(query,limit)
+
+ =20
+ def createTable(self, soClass):
+ #we create the table in a transaction because the addition of the
+ #table and the sequence must be atomic=20
+
+ #i tried to use the transaction class but i get a recursion limi=
t error =20
+ # t=3Dself.transaction()
+ # t.query('CREATE TABLE %s (\n%s\n)' % \
+ # (soClass._table, self.createColumns(soClass)))
+ # =09
+ # t.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._ta=
ble))
+ # t.commit()
+ =09
+ #so use transaction when the problem will be solved
+ self.query('CREATE TABLE %s (\n%s\n)' % \
+ (soClass._table, self.createColumns(soClass)))
+ self.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._tab=
le))
+=20
+=09
+ def createColumn(self, soClass, col):
+ return col.maxdbCreateSQL()
+=09
+ def createIDColumn(self, soClass):
+ return '%s INT PRIMARY KEY' % soClass._idName
+=09
+ def dropTable(self, tableName,cascade=3DFalse):
+ #we drop the table in a transaction because the removal of the
+ #table and the sequence must be atomic=20
+ #i tried to use the transaction class but i get a recursion limit erro=
r=09
+ # try:
+ # t=3Dself.transaction()
+ # t.query("DROP TABLE %s" % tableName)
+ # t.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+ # t.commit()
+ # except:t.rollback()
+ #so use transaction when the problem will be solved
+ self.query("DROP TABLE %s" % tableName)
+ self.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+=09
+ def joinSQLType(self, join):
+ return 'INT NOT NULL'
+=09
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll("SELECT OBJECT_NAME FROM ALL_OBJECTS WHE=
RE OBJECT_TYPE=3D'TABLE'"):
+ if table.lower() =3D=3D tableName.lower():
+ return True
+ return False
+ =20
+=09
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD %s' %
+ (tableName,
+ column.maxdbCreateSQL()))
+=09
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+=09
+
+
+
+ GET_COLUMNS =3D (" SELECT COLUMN_NAME,NULLABLE,DATA_DEFAULT,DATA_TYPE=
, DATA_LENGTH,DATA_SCALE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=3DUPPER('=
%s')")
+ GET_PK_AND_FK =3D (""" SELECT constraint_cols .column_name,constraints.=
constraint_type , refname,reftablename FROM
+ user_cons_columns constraint_cols=20
+ INNER JOIN user_constraints constraints ON constraint_cols.cons=
traint_name=3Dconstraints.constraint_name=20
+ LEFT OUTER JOIN show_foreign_key fk on constraint_cols.column_nam=
e=3Dfk.columnname
+ WHERE constraints.table_name =3DUPPER('%s')"""
+ )
+=09
+ def columnsFromSchema(self, tableName, soClass):
+ colData =3D self.queryAll(self.GET_COLUMNS
+ % tableName)
+ =09
+ results =3D []
+ keymap =3D {}
+ pkmap=3D{}
+ fkData =3D self.queryAll(self.GET_PK_AND_FK% tableName)
+ for col, cons_type, refcol, reftable in fkData:
+ col_name=3D col.lower()
+ pkmap[col_name]=3DFalse
+ if cons_type =3D=3D 'R':
+ keymap[col_name]=3Dreftable.lower()
+ =09
+ elif cons_type =3D=3D 'P':
+ pkmap[col_name]=3DTrue
+ =09
+ if len(pkmap) =3D=3D 0: raise PrimaryKeyNotFounded, tableName
+ =09
+ for field, nullAllowed, default, data_type, data_len, data_scale in co=
lData:
+ #id is defined as primary key --> ok
+ #We let sqlobject raise error if the 'id' is used for another column
+ field_name =3D field.lower()=20
+ if field_name =3D=3D 'id' and pkmap[field_name]:
+ continue
+ =09
+ colClass, kw =3D self.guessClass(data_type,data_len,data_scale)
+ kw['name'] =3D field_name
+ =09
+ if nullAllowed =3D=3D 'Y' :=20
+ nullAllowed=3DFalse
+ else:
+ nullAllowed=3DTrue
+ =09
+ kw['notNone'] =3D nullAllowed
+ if default is not None:
+ kw['default'] =3D default
+ =09
+ if keymap.has_key(field_name):
+ kw['foreignKey'] =3D keymap[field_name]
+ =09
+ results.append(colClass(**kw))
+ =20
+ return results
+ =20
+ _numericTypes=3D['INTEGER', 'INT','SMALLINT']
+ _dateTypes=3D['DATE','TIME','TIMESTAMP']
+=09
+ def guessClass(self, t, flength, fscale=3DNone):
+ """
+ An internal method that tries to figure out what Col subclass
+ is appropriate given whatever introspective information is
+ available -- both very database-specific.
+ """
+ if t in self._numericTypes:
+ return col.IntCol, {}
+ # The type returned by the sapdb library for LONG is SapDB_LongReader
+ #To get the data call the read member with desired size (default =3D-1=
means get all)
+ =09
+ elif t.find('LONG') !=3D -1:
+ return col.StringCol, {'length': flength,
+ 'varchar': False}
+ elif t in self._dateTypes:
+ return col.DateTimeCol, {}
+ elif t =3D=3D 'FIXED':
+ return CurrencyCol,{'size':flength,
+ 'precision':fscale}
+ else:
+ return col.Col, {}
\ No newline at end of file
Added: trunk/SQLObject/sqlobject/maxdb/maxdbconnection.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/sqlobject/maxdb/maxdbconnection.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
|
|
From: <sub...@co...> - 2004-06-14 12:04:59
|
Author: ahmedmo Date: 2004-06-14 04:02:26 -0400 (Mon, 14 Jun 2004) New Revision: 137 Added: trunk/SQLObject/sqlobject/maxdb/ Log: Created folder remotely |
|
From: <sub...@co...> - 2004-06-14 12:04:47
|
Author: ahmedmo Date: 2004-06-14 04:02:13 -0400 (Mon, 14 Jun 2004) New Revision: 136 Removed: trunk/SQLObject/maxdb/ Log: Removed file/folder |
|
From: <sub...@co...> - 2004-06-14 12:01:53
|
Author: ahmedmo
Date: 2004-06-14 03:59:20 -0400 (Mon, 14 Jun 2004)
New Revision: 135
Added:
trunk/SQLObject/converters.py
Log:
Added: trunk/SQLObject/converters.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/converters.py 2004-06-14 07:58:45 UTC (rev 134)
+++ trunk/SQLObject/converters.py 2004-06-14 07:59:20 UTC (rev 135)
@@ -0,0 +1,183 @@
+try:
+ import mx.DateTime.ISO
+ origISOStr =3D mx.DateTime.ISO.strGMT
+ from mx.DateTime import DateTimeType
+except ImportError:
+ try:
+ import DateTime.ISO
+ origISOStr =3D DateTime.ISO.strGMT
+ from DateTime import DateTimeType
+ except ImportError:
+ origISOStr =3D None
+ DateTimeType =3D None
+import time
+try:
+ import datetime
+except ImportError:
+ datetime =3D None
+
+try:
+ import Sybase
+ NumericType=3DSybase.NumericType
+except ImportError:
+ NumericType =3D None=20
+
+if type(1=3D=3D1) =3D=3D type(1):
+ class BOOL(object):
+ def __init__(self, value):
+ self.value =3D not not value
+ def __nonzero__(self):
+ return self.value
+ def __repr__(self):
+ if self:
+ return 'TRUE'
+ else:
+ return 'FALSE'
+ TRUE =3D BOOL(1)
+ FALSE =3D BOOL(0)
+else:
+ TRUE =3D 1=3D=3D1
+ FALSE =3D 0=3D=3D1
+
+from types import InstanceType, ClassType, TypeType
+
+########################################
+## Quoting
+########################################
+
+sqlStringReplace =3D [
+ ('\\', '\\\\'),
+ ("'", "''"),
+ ('\000', '\\0'),
+ ('\b', '\\b'),
+ ('\n', '\\n'),
+ ('\r', '\\r'),
+ ('\t', '\\t'),
+ ]
+
+def isoStr(val):
+ """
+ Gets rid of time zone information
+ (@@: should we convert to GMT?)
+ """
+ val =3D origISOStr(val)
+ if val.find('+') =3D=3D -1:
+ return val
+ else:
+ return val[:val.find('+')]
+
+class ConverterRegistry:
+
+ def __init__(self):
+ self.basic =3D {}
+ self.klass =3D {}
+
+ def registerConverter(self, typ, func):
+ if type(typ) is ClassType:
+ self.klass[typ] =3D func
+ else:
+ self.basic[typ] =3D func
+
+ def lookupConverter(self, value, default=3DNone):
+ if type(value) =3D=3D InstanceType:
+ # lookup on klasses dict
+ return self.klass.get(value.__class__, default)
+ return self.basic.get(type(value), default)
+
+converters =3D ConverterRegistry()
+registerConverter =3D converters.registerConverter
+lookupConverter =3D converters.lookupConverter
+
+def StringLikeConverter(value, db):
+ if db in ('mysql', 'postgres', 'sybase'):
+ for orig, repl in sqlStringReplace:
+ value =3D value.replace(orig, repl)
+ elif db in ('sqlite', 'firebird','maxdb'):
+ value =3D value.replace("'", "''")
+ else:
+ assert 0, "Database %s unknown" % db
+ return "'%s'" % value
+
+registerConverter(type(""), StringLikeConverter)
+registerConverter(type(u""), StringLikeConverter)
+
+def IntConverter(value, db):
+ return repr(int(value))
+
+registerConverter(type(1), IntConverter)
+registerConverter(type(0L), IntConverter)
+
+if NumericType:
+ registerConverter(NumericType, IntConverter)
+
+def BoolConverter(value, db):
+ if db in ('postgres',):
+ if value:
+ return "'t'"
+ else:
+ return "'f'"
+ else:
+ if value:
+ return '1'
+ else:
+ return '0'
+
+registerConverter(type(TRUE), BoolConverter)
+
+def FloatConverter(value, db):
+ return repr(value)
+
+registerConverter(type(1.0), FloatConverter)
+
+if DateTimeType:
+ def DateTimeConverter(value, db):
+ return "'%s'" % isoStr(value)
+
+ registerConverter(DateTimeType, DateTimeConverter)
+
+def NoneConverter(value, db):
+ return "NULL"
+
+registerConverter(type(None), NoneConverter)
+
+def SequenceConverter(value, db):
+ return "(%s)" % ", ".join([sqlrepr(v, db) for v in value])
+
+registerConverter(type(()), SequenceConverter)
+registerConverter(type([]), SequenceConverter)
+
+if hasattr(time, 'struct_time'):
+ def StructTimeConverter(value, db):
+ return time.strftime("'%Y-%m-%d %H:%M:%S'", value)
+
+ registerConverter(time.struct_time, StructTimeConverter)
+
+if datetime:
+ def DateTimeConverter(value, db):
+ return value.strftime("'%Y-%m-%d %H:%M:%s'")
+
+ registerConverter(datetime.datetime, DateTimeConverter)
+
+ def TimeConverter(value, db):
+ return value.strftime("'%H:%M:%s'")
+
+ registerConverter(datetime.time, TimeConverter)
+
+ def DateConverter(value, db):
+ return value.strftime("'%Y-%m-%d'")
+
+ registerConverter(datetime.date, DateConverter)
+
+def sqlrepr(obj, db=3DNone):
+ try:
+ reprFunc =3D obj.__sqlrepr__
+ except AttributeError:
+ converter =3D lookupConverter(obj)
+ if converter is None:
+ raise ValueError, "Unknown SQL builtin type: %s for %s" % \
+ (type(obj), repr(obj))
+ return converter(obj, db)
+ else:
+ return reprFunc(db)
+
+
|
|
From: <sub...@co...> - 2004-06-14 12:01:20
|
Author: ahmedmo
Date: 2004-06-14 03:58:45 -0400 (Mon, 14 Jun 2004)
New Revision: 134
Added:
trunk/SQLObject/col.py
Log:
Added: trunk/SQLObject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/col.py 2004-06-14 07:52:42 UTC (rev 133)
+++ trunk/SQLObject/col.py 2004-06-14 07:58:45 UTC (rev 134)
@@ -0,0 +1,612 @@
+"""
+Col
+"""
+
+import sqlbuilder
+import re
+# Sadly the name "constraints" conflicts with many of the function
+# arguments in this module, so we rename it:
+import constraints as consts
+from include import validators
+
+NoDefault =3D sqlbuilder.NoDefault
+True, False =3D 1=3D=3D1, 0=3D=3D1
+ =20
+
+########################################
+## Columns
+########################################
+
+# Col is essentially a column definition, it doesn't have
+# much logic to it.
+class SOCol(object):
+
+ def __init__(self,
+ name,
+ soClass,
+ dbName=3DNone,
+ default=3DNoDefault,
+ foreignKey=3DNone,
+ alternateID=3DFalse,
+ alternateMethodName=3DNone,
+ constraints=3DNone,
+ notNull=3DNoDefault,
+ notNone=3DNoDefault,
+ unique=3DNoDefault,
+ sqlType=3DNone,
+ columnDef=3DNone,
+ validator=3DNone,
+ immutable=3DFalse,
+ cascade=3DNone,
+ lazy=3DFalse,
+ noCache=3DFalse):
+
+ # This isn't strictly true, since we *could* use backquotes or
+ # " or something (database-specific) around column names, but
+ # why would anyone *want* to use a name like that?
+ # @@: I suppose we could actually add backquotes to the
+ # dbName if we needed to...
+ assert sqlbuilder.sqlIdentifier(name), 'Name must be SQL-safe (l=
etters, numbers, underscores): %s' \
+ % repr(name)
+ assert name !=3D 'id', 'The column name "id" is reserved for SQL=
Object use (and is implicitly created).'
+ assert name, "You must provide a name for all columns"
+
+ self.columnDef =3D columnDef
+
+ self.immutable =3D immutable
+
+ # cascade can be one of:
+ # None: no constraint is generated
+ # True: a CASCADE constraint is generated
+ # False: a RESTRICT constraint is generated
+ self.cascade =3D cascade
+
+ if type(constraints) not in (type([]), type(())):
+ constraints =3D [constraints]
+ self.constraints =3D self.autoConstraints() + constraints
+
+ self.notNone =3D False
+ if notNull is not NoDefault:
+ self.notNone =3D notNull
+ assert notNone is NoDefault or \
+ (not notNone) =3D=3D (not notNull), \
+ "The notNull and notNone arguments are aliases, and m=
ust not conflict. You gave notNull=3D%r, notNone=3D%r" % (notNull, notNo=
ne)
+ elif notNone is not NoDefault:
+ self.notNone =3D notNone
+ if self.notNone:
+ self.constraints =3D [consts.notNull] + self.constraints
+
+ self.name =3D name
+ self.soClass =3D None
+ self._default =3D default
+ self.customSQLType =3D sqlType
+
+ self.foreignKey =3D foreignKey
+ if self.foreignKey:
+ #assert self.name.upper().endswith('ID'), "All foreign key c=
olumns must end with 'ID' (%s)" % repr(self.name)
+ if not self.name.upper().endswith('ID'):
+ self.foreignName =3D self.name
+ self.name =3D self.name + "ID"
+ else:
+ self.foreignName =3D self.name[:-2]
+ else:
+ self.foreignName =3D None
+
+ # if they don't give us a specific database name for
+ # the column, we separate the mixedCase into mixed_case
+ # and assume that.
+ if dbName is None:
+ self.dbName =3D soClass._style.pythonAttrToDBColumn(self.nam=
e)
+ else:
+ self.dbName =3D dbName
+
+ # alternateID means that this is a unique column that
+ # can be used to identify rows
+ self.alternateID =3D alternateID
+ if self.alternateID and alternateMethodName is None:
+ self.alternateMethodName =3D 'by' + self.name[0].capitalize(=
) + self.name[1:]
+ else:
+ self.alternateMethodName =3D alternateMethodName
+
+ if unique is NoDefault:
+ self.unique =3D alternateID
+ else:
+ self.unique =3D unique
+
+ self.validator =3D validator
+ self.noCache =3D noCache
+ self.lazy =3D lazy
+
+ def _set_validator(self, value):
+ self._validator =3D value
+ if self._validator:
+ self.toPython =3D self._validator.toPython
+ self.fromPython =3D self._validator.fromPython
+ else:
+ self.toPython =3D None
+ self.fromPython =3D None
+
+ def _get_validator(self):
+ return self._validator
+
+ validator =3D property(_get_validator, _set_validator)
+
+ def autoConstraints(self):
+ return []
+
+ def _get_default(self):
+ # A default can be a callback or a plain value,
+ # here we resolve the callback
+ if self._default is NoDefault:
+ return NoDefault
+ elif hasattr(self._default, '__sqlrepr__'):
+ return self._default
+ elif callable(self._default):
+ return self._default()
+ else:
+ return self._default
+ default =3D property(_get_default, None, None)
+
+ def _get_joinName(self):
+ assert self.name[-2:] =3D=3D 'ID'
+ return self.name[:-2]
+ joinName =3D property(_get_joinName, None, None)
+
+ def __repr__(self):
+ r =3D '<%s %s' % (self.__class__.__name__, self.name)
+ if self.default is not NoDefault:
+ r +=3D ' default=3D%s' % repr(self.default)
+ if self.foreignKey:
+ r +=3D ' connected to %s' % self.foreignKey
+ if self.alternateID:
+ r +=3D ' alternate ID'
+ if self.notNone:
+ r +=3D ' not null'
+ return r + '>'
+
+ def createSQL(self):
+ return ' '.join([self._sqlType() + self._extraSQL()])
+
+ def _extraSQL(self):
+ result =3D []
+ if self.notNone or self.alternateID:
+ result.append('NOT NULL')
+ if self.unique or self.alternateID:
+ result.append('UNIQUE')
+ return result
+
+ def _sqlType(self):
+ if self.customSQLType is None:
+ raise ValueError, ("Col %s (%s) cannot be used for automatic=
"
+ "schema creation (too abstract)" %
+ (self.name, self.__class__))
+ else:
+ return self.customSQLType
+
+ def _mysqlType(self):
+ return self._sqlType()
+
+ def _postgresType(self):
+ return self._sqlType()
+
+ def _sqliteType(self):
+ # SQLite is naturally typeless, so as a fallback it uses
+ # no type.
+ try:
+ return self._sqlType()
+ except ValueError:
+ return ''
+
+ def _sybaseType(self):
+ return self._sqlType()
+
+ def _firebirdType(self):
+ return self._sqlType()
+ =20
+ def _maxdbType(self):
+ return self._sqlType() =20
+ =20
+ def mysqlCreateSQL(self):
+ return ' '.join([self.dbName, self._mysqlType()] + self._extraSQ=
L())
+
+ def postgresCreateSQL(self):
+ return ' '.join([self.dbName, self._postgresType()] + self._extr=
aSQL())
+
+ def sqliteCreateSQL(self):
+ return ' '.join([self.dbName, self._sqliteType()] + self._extraS=
QL())
+
+ def sybaseCreateSQL(self):
+ return ' '.join([self.dbName, self._sybaseType()] + self._extraS=
QL())
+
+ def firebirdCreateSQL(self):
+ # Ian Sparks pointed out that fb is picky about the order
+ # of the NOT NULL clause in a create statement. So, we handle
+ # them differently for Enum columns.
+ if not isinstance(self, SOEnumCol):
+ return ' '.join([self.dbName, self._firebirdType()] + self._=
extraSQL())
+ else:
+ return ' '.join([self.dbName] + [self._firebirdType()[0]] + =
self._extraSQL() + [self._firebirdType()[1]])
+ =20
+ def maxdbCreateSQL(self):
+ return ' '.join([self.dbName, self._maxdbType()] + self._extraSQ=
L())
+
+ def __get__(self, obj, type=3DNone):
+ if obj is None:
+ # class attribute, return the descriptor itself
+ return self
+ if obj.sqlmeta.obsolete:
+ raise '@@: figure out the exception for a delete'
+ if obj.sqlmeta.cacheColumns:
+ columns =3D obj.sqlmeta._columnCache
+ if columns is None:
+ obj.sqlmeta.loadValues()
+ try:
+ return columns[name]
+ except KeyError:
+ return obj.sqlmeta.loadColumn(self)
+ else:
+ return obj.sqlmeta.loadColumn(self)
+
+ def __set__(self, obj, value):
+ if self.immutable:
+ raise AttributeError("The column %s.%s is immutable" %
+ (obj.__class__.__name__,
+ self.name))
+ obj.sqlmeta.setColumn(self, value)
+
+ def __delete__(self, obj):
+ raise AttributeError("I can't be deleted from %r" % obj)
+
+
+class Col(object):
+
+ baseClass =3D SOCol
+
+ def __init__(self, name=3DNone, **kw):
+ kw['name'] =3D name
+ kw['columnDef'] =3D self
+ self.kw =3D kw
+
+ def setName(self, value):
+ assert self.kw['name'] is None, "You cannot change a name after =
it has already been set (from %s to %s)" % (self.kw['name'], value)
+ self.kw['name'] =3D value
+
+ def withClass(self, soClass):
+ return self.baseClass(soClass=3DsoClass, **self.kw)
+
+class SOStringCol(SOCol):
+
+ # 3-03 @@: What about BLOB?
+
+ def __init__(self, **kw):
+ self.length =3D popKey(kw, 'length')
+ self.varchar =3D popKey(kw, 'varchar', 'auto')
+ if not self.length:
+ assert self.varchar =3D=3D 'auto' or not self.varchar, \
+ "Without a length strings are treated as TEXT, not va=
rchar"
+ self.varchar =3D False
+ elif self.varchar =3D=3D 'auto':
+ self.varchar =3D True
+
+ SOCol.__init__(self, **kw)
+
+ def autoConstraints(self):
+ constraints =3D [consts.isString]
+ if self.length is not None:
+ constraints +=3D [consts.MaxLength(self.length)]
+ return constraints
+
+ def _sqlType(self):
+ if not self.length:
+ return 'TEXT'
+ elif self.varchar:
+ return 'VARCHAR(%i)' % self.length
+ else:
+ return 'CHAR(%i)' % self.length
+
+ def _firebirdType(self):
+ if not self.length:
+ return 'BLOB SUB_TYPE TEXT'
+ else:
+ return self._sqlType()
+ =20
+ def _maxdbType(self):
+ if not self.length:
+ return 'LONG ASCII'
+ else:
+ return self._sqlType()
+
+class StringCol(Col):
+ baseClass =3D SOStringCol
+
+class SOIntCol(SOCol):
+
+ # 3-03 @@: support precision, maybe max and min directly
+
+ def autoConstraints(self):
+ return [consts.isInt]
+
+ def _sqlType(self):
+ return 'INT'
+ =20
+ def _maxdbType(self):
+ return 'INT'
+
+class IntCol(Col):
+ baseClass =3D SOIntCol
+
+class BoolValidator(validators.Validator):
+
+ def fromPython(self, value, state):
+ if value:
+ return sqlbuilder.TRUE
+ else:
+ return sqlbuilder.FALSE
+
+ def toPython(self, value, state):
+ if not value or not int(value):
+ return sqlbuilder.FALSE
+ else:
+ return sqlbuilder.TRUE
+
+class SOBoolCol(SOCol):
+
+ def __init__(self, **kw):
+ SOCol.__init__(self, **kw)
+ self.validator =3D validators.All.join(BoolValidator(), self.val=
idator)
+
+ def autoConstraints(self):
+ return [consts.isBool]
+
+ def _postgresType(self):
+ return 'BOOL'
+
+ def _mysqlType(self):
+ return "TINYINT"
+
+ def _sybaseType(self):
+ return "BIT"
+
+ def _firebirdType(self):
+ return 'INT'
+ =20
+ def _maxdbType(self):
+ return "BOOLEAN"
+
+class BoolCol(Col):
+ baseClass =3D SOBoolCol
+
+class SOFloatCol(SOCol):
+
+ # 3-03 @@: support precision (e.g., DECIMAL)
+
+ def autoConstraints(self):
+ return [consts.isFloat]
+
+ def _sqlType(self):
+ return 'FLOAT'
+
+class FloatCol(Col):
+ baseClass =3D SOFloatCol
+
+class SOKeyCol(SOCol):
+
+ # 3-03 @@: this should have a simplified constructor
+ # Should provide foreign key information for other DBs.
+
+ def _mysqlType(self):
+ return 'INT'
+
+ def _sqliteType(self):
+ return 'INT'
+
+ def _postgresType(self):
+ return 'INT'
+
+ def _sybaseType(self):
+ return 'INT'
+
+ def _firebirdType(self):
+ return 'INT'
+ =20
+ def _maxdbType(self):
+ return 'INT'
+
+class KeyCol(Col):
+
+ baseClass =3D SOKeyCol
+
+class SOForeignKey(SOKeyCol):
+
+ def __init__(self, **kw):
+ foreignKey =3D kw['foreignKey']
+ style =3D kw['soClass']._style
+ if not kw.get('name'):
+ kw['name'] =3D style.instanceAttrToIDAttr(style.pythonClassT=
oAttr(foreignKey))
+ else:
+ if not kw['name'].upper().endswith('ID'):
+ kw['name'] =3D style.instanceAttrToIDAttr(kw['name'])
+ SOKeyCol.__init__(self, **kw)
+
+ def postgresCreateSQL(self):
+ from main import findClass
+ sql =3D SOKeyCol.postgresCreateSQL(self)
+ if self.cascade is not None:
+ other =3D findClass(self.foreignKey)
+ tName =3D other._table
+ idName =3D other._idName
+ action =3D self.cascade and 'CASCADE' or 'RESTRICT'
+ constraint =3D ('CONSTRAINT %(tName)s_exists '
+ 'FOREIGN KEY(%(colName)s) '
+ 'REFERENCES %(tName)s(%(idName)s) '
+ 'ON DELETE %(action)s' %
+ {'tName':tName,
+ 'colName':self.dbName,
+ 'idName':idName,
+ 'action':action})
+ sql =3D ', '.join([sql, constraint])
+ return sql
+
+ def sybaseCreateSQL(self):
+ from SQLObject import findClass
+ sql =3D SOKeyCol.sybaseCreateSQL(self)
+ other =3D findClass(self.foreignKey)
+ tName =3D other._table
+ idName =3D other._idName
+ reference =3D ('REFERENCES %(tName)s(%(idName)s) ' %
+ {'tName':tName,
+ 'idName':idName})
+ sql =3D ' '.join([sql, reference])
+ return sql
+ =20
+ def maxdbCreateSQL(self):
+ from main import findClass
+ other =3D findClass(self.foreignKey)
+ fidName =3D self.dbName
+ #I assume that foreign key name is identical to the id of the referenc=
e table =09
+ sql =3D ' '.join([fidName, self._maxdbType()])
+ tName =3D other._table
+ idName =3D other._idName
+ sql=3Dsql + ',' + '\n'=20
+ sql=3Dsql + 'FOREIGN KEY (%s) REFERENCES %s(%s)'%(fidName,tName,idName=
)
+ return sql
+
+class ForeignKey(KeyCol):
+
+ baseClass =3D SOForeignKey
+
+ def __init__(self, foreignKey=3DNone, **kw):
+ KeyCol.__init__(self, foreignKey=3DforeignKey, **kw)
+
+class SOEnumCol(SOCol):
+
+ def __init__(self, **kw):
+ self.enumValues =3D popKey(kw, 'enumValues', None)
+ assert self.enumValues is not None, \
+ 'You must provide an enumValues keyword argument'
+ SOCol.__init__(self, **kw)
+
+ def autoConstraints(self):
+ return [consts.isString, consts.InList(self.enumValues)]
+
+ def _mysqlType(self):
+ return "ENUM(%s)" % ', '.join([sqlbuilder.sqlrepr(v, 'mysql') fo=
r v in self.enumValues])
+
+ def _postgresType(self):
+ length =3D max(map(len, self.enumValues))
+ enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'postgres') for =
v in self.enumValues])
+ checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
+ return "VARCHAR(%i) %s" % (length, checkConstraint)
+
+ def _sqliteType(self):
+ return self._postgresType()
+
+ def _sybaseType(self):
+ return self._postgresType()
+
+ def _firebirdType(self):
+ length =3D max(map(len, self.enumValues))
+ enumValues =3D ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for =
v in self.enumValues])
+ checkConstraint =3D "CHECK (%s in (%s))" % (self.dbName, enumVal=
ues)
+ #NB. Return a tuple, not a string here
+ return "VARCHAR(%i)" % (length), checkConstraint
+ =20
+ def _maxdbType(self):
+ raise "Enum type is not supported"
+ =20
+
+class EnumCol(Col):
+ baseClass =3D SOEnumCol
+
+class SODateTimeCol(SOCol):
+
+ # 3-03 @@: provide constraints; right now we let the database
+ # do any parsing and checking. And DATE and TIME?
+
+ def _mysqlType(self):
+ return 'DATETIME'
+
+ def _postgresType(self):
+ return 'TIMESTAMP'
+
+ def _sybaseType(self):
+ return 'DATETIME'
+
+ def _sqliteType(self):
+ return 'TIMESTAMP'
+
+ def _firebirdType(self):
+ return 'TIMESTAMP'
+ =20
+ def _maxdbType(self):
+ return 'TIMESTAMP'
+
+class DateTimeCol(Col):
+ baseClass =3D 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()
+
+ def _firebirdType(self):
+ return 'DATE'
+ =20
+ def _maxdbType(self):
+ return 'DATE'
+
+class DateCol(Col):
+ baseClass =3D SODateCol
+
+class SODecimalCol(SOCol):
+
+ def __init__(self, **kw):
+ self.size =3D popKey(kw, 'size', NoDefault)
+ assert self.size is not NoDefault, \
+ "You must give a size argument"
+ self.precision =3D popKey(kw, 'precision', NoDefault)
+ assert self.precision is not NoDefault, \
+ "You must give a precision argument"
+ SOCol.__init__(self, **kw)
+
+ def _sqlType(self):
+ return 'DECIMAL(%i, %i)' % (self.size, self.precision)
+
+class DecimalCol(Col):
+ baseClass =3D SODecimalCol
+
+class SOCurrencyCol(SODecimalCol):
+
+ def __init__(self, **kw):
+ pushKey(kw, 'size', 10)
+ pushKey(kw, 'precision', 2)
+ SODecimalCol.__init__(self, **kw)
+
+class CurrencyCol(DecimalCol):
+ baseClass =3D SOCurrencyCol
+
+def popKey(kw, name, default=3DNone):
+ if not kw.has_key(name):
+ return default
+ value =3D kw[name]
+ del kw[name]
+ return value
+
+def pushKey(kw, name, value):
+ if not kw.has_key(name):
+ kw[name] =3D value
+
+all =3D []
+for key, value in globals().items():
+ if isinstance(value, type) and issubclass(value, Col):
+ all.append(key)
+__all__ =3D all
|
|
From: <sub...@co...> - 2004-06-14 11:55:21
|
Author: ahmedmo
Date: 2004-06-14 03:52:42 -0400 (Mon, 14 Jun 2004)
New Revision: 133
Added:
trunk/SQLObject/maxdb/__init__.py
trunk/SQLObject/maxdb/__init__.pyc
trunk/SQLObject/maxdb/maxdbconnection.py
trunk/SQLObject/maxdb/maxdbconnection.pyc
Log:
Initial Import
Added: trunk/SQLObject/maxdb/__init__.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/maxdb/__init__.py 2004-06-14 07:52:22 UTC (rev 132)
+++ trunk/SQLObject/maxdb/__init__.py 2004-06-14 07:52:42 UTC (rev 133)
@@ -0,0 +1,14 @@
+from sqlobject.dbconnection import registerConnection
+
+def builder():
+ import maxdbconnection
+ return maxdbconnection.MaxdbConnection
+
+def isSupported():
+ try:
+ import sapdb
+ except ImportError:
+ return False
+ return False
+
+registerConnection(['maxdb','sapdb'],builder, isSupported)
Added: trunk/SQLObject/maxdb/__init__.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/maxdb/__init__.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/SQLObject/maxdb/maxdbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/maxdb/maxdbconnection.py 2004-06-14 07:52:22 UTC (rev=
132)
+++ trunk/SQLObject/maxdb/maxdbconnection.py 2004-06-14 07:52:42 UTC (rev=
133)
@@ -0,0 +1,276 @@
+"""
+Contributed by Edigram SAS,Paris=20
+Ahmed MOHAMED ALI <ahm...@ya...> 27 April 2004
+This program 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.
+
+connection creation sample=20
+__connection__ =3D DBConnection.maxdbConnection(
+ host=3Dhostname, database=3Ddbname,
+ user=3Duser_name, password=3Duser_password,autoCommit=3D1,debug=3D1)
+"""
+from sqlobject.dbconnection import DBAPI
+from sqlobject import col
+dbapi =3D None
+
+
+
+class maxdbException(Exception):
+ def __init__(self, value):
+ self.value =3D value
+ def __str__(self):
+ return repr(self.value)
+=09
+class LowerBoundOfSliceIsNotSupported(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'')
+=09
+
+class IncorrectIDStyleError(maxdbException) :
+ def __init__(self,value):
+ maxdbException.__init__(self,'This primary key name is not in the exp=
ected style,please rename the column to %s or switch to another style'%(v=
alue))
+
+class StyleMismatchError(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'The name %s is only permitted for primar=
y key,change the column name or switch to another style'%value)
+
+
+class PrimaryKeyNotFounded(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,"No primary key was defined on table %s"%=
(value))
+
+ =09
+SAPDBMAX_ID_LENGTH=3D32 =20
+ =09
+class MaxdbConnection(DBAPI):
+
+ =20
+ supportTransactions =3D True
+ dbName =3D 'maxdb'
+ schemes =3D [dbName]
+ =20
+ def __init__ (self, user, password, database, host =3D '',autoCommit=3D=
1,sqlmode=3D'internal',isolation=3DNone,timeout=3DNone, **kw):
+ global dbapi
+ if dbapi is None:
+ from sapdb import dbapi
+ self.autoCommit =3D autoCommit
+ self.user =3D user
+ self.password =3D password
+ self.database =3D database
+ self.host =3D host
+ self.sqlmode =3D sqlmode
+ self.isolation =3D isolation
+ self.timeout =3D timeout
+ =20
+ DBAPI.__init__(self, **kw)
+ =20
+ def connectionFromURI(cls, uri):
+ auth, password, host, path, args =3D cls._parseURI(uri)
+ path =3D path.replace('/', os.path.sep)
+ return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **args)
+ connectionFromURI =3D classmethod(connectionFromURI)
+=09
+ =09
+ def _getConfigParams(self,sqlmode,auto):
+ autocommit=3D'off'
+ if auto:autocommit=3D'on'
+ opt=3D{}
+ opt["autocommit"]=3Dautocommit
+ opt["sqlmode"]=3Dsqlmode
+ if self.isolation:
+ opt["isolation"]=3Dself.isolation
+ if self.timeout :
+ opt["timeout"]=3Dself.timeout
+ =09
+ return opt
+ =09
+ def _setAutoCommit(self, conn, auto):
+ conn.close()
+ conn.__init__(self.user, self.password, self.database, self.host,**sel=
f._getConfigParams(self.sqlmode,auto))
+ =09
+ =20
+=09
+ =20
+ def createSequenceName(self,table):
+ """ sequence name are builded with the concatenation of the table name=
with '_SEQ' word
+ we truncate the name of the sequence_name because
+ sapdb identifier cannot exceed 32 characters
+ so that the name of the sequence does not exceed 32 characters
+ """
+ return '%s_SEQ'%(table[:SAPDBMAX_ID_LENGTH -4])
+=09
+ def makeConnection(self):
+ conn =3D dbapi.Connection(self.user, self.password, self.database, se=
lf.host,**self._getConfigParams(self.sqlmode,self.autoCommit) )
+ return conn
+=09
+ def _queryInsertID(self, conn, table, idName, id, names, values):
+ c =3D conn.cursor()
+ if id is None:
+ c.execute('SELECT %s.NEXTVAL FROM DUAL' % (self.createSequenceName(ta=
ble)))
+ id =3D c.fetchone()[0]
+ names =3D [idName] + names
+ values =3D [id] + values
+ q =3D self._insertSQL(table, names, values)
+ if self.debug:
+ self.printDebug(conn, q, 'QueryIns')
+ c.execute(q)
+ if self.debugOutput:
+ self.printDebug(conn, id, 'QueryIns', 'result')
+ return id
+=09
+ def sqlAddLimit(self,query,limit):
+ sql =3D query
+ sql =3D sql.replace("SELECT","SELECT ROWNO, ")
+ if sql.find('WHERE') !=3D -1:
+ sql =3D sql + ' AND ' + limit
+ else:=09
+ sql =3D sql + 'WHERE ' + limit
+
+ return sql
+ =09
+ def _queryAddLimitOffset(self, query, start, end):
+ if start: raise LowerBoundOfSliceIsNotSupported
+ limit =3D ' ROWNO <=3D %d ' % (end)
+ return self.sqlAddLimit(query,limit)
+
+ =20
+ def createTable(self, soClass):
+ #we create the table in a transaction because the addition of the
+ #table and the sequence must be atomic=20
+
+ #i tried to use the transaction class but i get a recursion limi=
t error =20
+ # t=3Dself.transaction()
+ # t.query('CREATE TABLE %s (\n%s\n)' % \
+ # (soClass._table, self.createColumns(soClass)))
+ # =09
+ # t.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._ta=
ble))
+ # t.commit()
+ =09
+ #so use transaction when the problem will be solved
+ self.query('CREATE TABLE %s (\n%s\n)' % \
+ (soClass._table, self.createColumns(soClass)))
+ self.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._tab=
le))
+=20
+=09
+ def createColumn(self, soClass, col):
+ return col.maxdbCreateSQL()
+=09
+ def createIDColumn(self, soClass):
+ return '%s INT PRIMARY KEY' % soClass._idName
+=09
+ def dropTable(self, tableName,cascade=3DFalse):
+ #we drop the table in a transaction because the removal of the
+ #table and the sequence must be atomic=20
+ #i tried to use the transaction class but i get a recursion limit erro=
r=09
+ # try:
+ # t=3Dself.transaction()
+ # t.query("DROP TABLE %s" % tableName)
+ # t.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+ # t.commit()
+ # except:t.rollback()
+ #so use transaction when the problem will be solved
+ self.query("DROP TABLE %s" % tableName)
+ self.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+=09
+ def joinSQLType(self, join):
+ return 'INT NOT NULL'
+=09
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll("SELECT OBJECT_NAME FROM ALL_OBJECTS WHE=
RE OBJECT_TYPE=3D'TABLE'"):
+ if table.lower() =3D=3D tableName.lower():
+ return True
+ return False
+ =20
+=09
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD %s' %
+ (tableName,
+ column.maxdbCreateSQL()))
+=09
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+=09
+
+
+
+ GET_COLUMNS =3D (" SELECT COLUMN_NAME,NULLABLE,DATA_DEFAULT,DATA_TYPE=
, DATA_LENGTH,DATA_SCALE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=3DUPPER('=
%s')")
+ GET_PK_AND_FK =3D (""" SELECT constraint_cols .column_name,constraints.=
constraint_type , refname,reftablename FROM
+ user_cons_columns constraint_cols=20
+ INNER JOIN user_constraints constraints ON constraint_cols.cons=
traint_name=3Dconstraints.constraint_name=20
+ LEFT OUTER JOIN show_foreign_key fk on constraint_cols.column_nam=
e=3Dfk.columnname
+ WHERE constraints.table_name =3DUPPER('%s')"""
+ )
+=09
+ def columnsFromSchema(self, tableName, soClass):
+ colData =3D self.queryAll(self.GET_COLUMNS
+ % tableName)
+ =09
+ results =3D []
+ keymap =3D {}
+ pkmap=3D{}
+ fkData =3D self.queryAll(self.GET_PK_AND_FK% tableName)
+ for col, cons_type, refcol, reftable in fkData:
+ col_name=3D col.lower()
+ pkmap[col_name]=3DFalse
+ if cons_type =3D=3D 'R':
+ keymap[col_name]=3Dreftable.lower()
+ =09
+ elif cons_type =3D=3D 'P':
+ pkmap[col_name]=3DTrue
+ =09
+ if len(pkmap) =3D=3D 0: raise PrimaryKeyNotFounded, tableName
+ =09
+ for field, nullAllowed, default, data_type, data_len, data_scale in co=
lData:
+ #id is defined as primary key --> ok
+ #We let sqlobject raise error if the 'id' is used for another column
+ field_name =3D field.lower()=20
+ if field_name =3D=3D 'id' and pkmap[field_name]:
+ continue
+ =09
+ colClass, kw =3D self.guessClass(data_type,data_len,data_scale)
+ kw['name'] =3D field_name
+ =09
+ if nullAllowed =3D=3D 'Y' :=20
+ nullAllowed=3DFalse
+ else:
+ nullAllowed=3DTrue
+ =09
+ kw['notNone'] =3D nullAllowed
+ if default is not None:
+ kw['default'] =3D default
+ =09
+ if keymap.has_key(field_name):
+ kw['foreignKey'] =3D keymap[field_name]
+ =09
+ results.append(colClass(**kw))
+ =20
+ return results
+ =20
+ _numericTypes=3D['INTEGER', 'INT','SMALLINT']
+ _dateTypes=3D['DATE','TIME','TIMESTAMP']
+=09
+ def guessClass(self, t, flength, fscale=3DNone):
+ """
+ An internal method that tries to figure out what Col subclass
+ is appropriate given whatever introspective information is
+ available -- both very database-specific.
+ """
+ if t in self._numericTypes:
+ return col.IntCol, {}
+ # The type returned by the sapdb library for LONG is SapDB_LongReader
+ #To get the data call the read member with desired size (default =3D-1=
means get all)
+ =09
+ elif t.find('LONG') !=3D -1:
+ return col.StringCol, {'length': flength,
+ 'varchar': False}
+ elif t in self._dateTypes:
+ return col.DateTimeCol, {}
+ elif t =3D=3D 'FIXED':
+ return CurrencyCol,{'size':flength,
+ 'precision':fscale}
+ else:
+ return col.Col, {}
\ No newline at end of file
Added: trunk/SQLObject/maxdb/maxdbconnection.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/maxdb/maxdbconnection.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
|
|
From: <sub...@co...> - 2004-06-14 11:54:56
|
Author: ahmedmo Date: 2004-06-14 03:52:22 -0400 (Mon, 14 Jun 2004) New Revision: 132 Removed: trunk/SQLObject/__init__.py Log: Removed file/folder Deleted: trunk/SQLObject/__init__.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/SQLObject/__init__.py 2004-06-14 07:52:16 UTC (rev 131) +++ trunk/SQLObject/__init__.py 2004-06-14 07:52:22 UTC (rev 132) @@ -1,14 +0,0 @@ -from sqlobject.dbconnection import registerConnection - -def builder(): - import maxdbconnection - return maxdbconnection.MaxdbConnection - -def isSupported(): - try: - import sapdb - except ImportError: - return False - return False - -registerConnection(['maxdb','sapdb'],builder, isSupported) |
|
From: <sub...@co...> - 2004-06-14 11:54:48
|
Author: ahmedmo Date: 2004-06-14 03:52:16 -0400 (Mon, 14 Jun 2004) New Revision: 131 Removed: trunk/SQLObject/__init__.pyc Log: Removed file/folder Deleted: trunk/SQLObject/__init__.pyc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) |
|
From: <sub...@co...> - 2004-06-14 11:54:43
|
Author: ahmedmo
Date: 2004-06-14 03:52:09 -0400 (Mon, 14 Jun 2004)
New Revision: 130
Removed:
trunk/SQLObject/maxdbconnection.py
Log:
Removed file/folder
Deleted: trunk/SQLObject/maxdbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/maxdbconnection.py 2004-06-14 07:52:01 UTC (rev 129)
+++ trunk/SQLObject/maxdbconnection.py 2004-06-14 07:52:09 UTC (rev 130)
@@ -1,276 +0,0 @@
-"""
-Contributed by Edigram SAS,Paris=20
-Ahmed MOHAMED ALI <ahm...@ya...> 27 April 2004
-This program 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.
-
-connection creation sample=20
-__connection__ =3D DBConnection.maxdbConnection(
- host=3Dhostname, database=3Ddbname,
- user=3Duser_name, password=3Duser_password,autoCommit=3D1,debug=3D1)
-"""
-from sqlobject.dbconnection import DBAPI
-from sqlobject import col
-dbapi =3D None
-
-
-
-class maxdbException(Exception):
- def __init__(self, value):
- self.value =3D value
- def __str__(self):
- return repr(self.value)
-=09
-class LowerBoundOfSliceIsNotSupported(maxdbException):
- def __init__(self, value):
- maxdbException.__init__(self,'')
-=09
-
-class IncorrectIDStyleError(maxdbException) :
- def __init__(self,value):
- maxdbException.__init__(self,'This primary key name is not in the exp=
ected style,please rename the column to %s or switch to another style'%(v=
alue))
-
-class StyleMismatchError(maxdbException):
- def __init__(self, value):
- maxdbException.__init__(self,'The name %s is only permitted for primar=
y key,change the column name or switch to another style'%value)
-
-
-class PrimaryKeyNotFounded(maxdbException):
- def __init__(self, value):
- maxdbException.__init__(self,"No primary key was defined on table %s"%=
(value))
-
- =09
-SAPDBMAX_ID_LENGTH=3D32 =20
- =09
-class MaxdbConnection(DBAPI):
-
- =20
- supportTransactions =3D True
- dbName =3D 'maxdb'
- schemes =3D [dbName]
- =20
- def __init__ (self, user, password, database, host =3D '',autoCommit=3D=
1,sqlmode=3D'internal',isolation=3DNone,timeout=3DNone, **kw):
- global dbapi
- if dbapi is None:
- from sapdb import dbapi
- self.autoCommit =3D autoCommit
- self.user =3D user
- self.password =3D password
- self.database =3D database
- self.host =3D host
- self.sqlmode =3D sqlmode
- self.isolation =3D isolation
- self.timeout =3D timeout
- =20
- DBAPI.__init__(self, **kw)
- =20
- def connectionFromURI(cls, uri):
- auth, password, host, path, args =3D cls._parseURI(uri)
- path =3D path.replace('/', os.path.sep)
- return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **args)
- connectionFromURI =3D classmethod(connectionFromURI)
-=09
- =09
- def _getConfigParams(self,sqlmode,auto):
- autocommit=3D'off'
- if auto:autocommit=3D'on'
- opt=3D{}
- opt["autocommit"]=3Dautocommit
- opt["sqlmode"]=3Dsqlmode
- if self.isolation:
- opt["isolation"]=3Dself.isolation
- if self.timeout :
- opt["timeout"]=3Dself.timeout
- =09
- return opt
- =09
- def _setAutoCommit(self, conn, auto):
- conn.close()
- conn.__init__(self.user, self.password, self.database, self.host,**sel=
f._getConfigParams(self.sqlmode,auto))
- =09
- =20
-=09
- =20
- def createSequenceName(self,table):
- """ sequence name are builded with the concatenation of the table name=
with '_SEQ' word
- we truncate the name of the sequence_name because
- sapdb identifier cannot exceed 32 characters
- so that the name of the sequence does not exceed 32 characters
- """
- return '%s_SEQ'%(table[:SAPDBMAX_ID_LENGTH -4])
-=09
- def makeConnection(self):
- conn =3D dbapi.Connection(self.user, self.password, self.database, se=
lf.host,**self._getConfigParams(self.sqlmode,self.autoCommit) )
- return conn
-=09
- def _queryInsertID(self, conn, table, idName, id, names, values):
- c =3D conn.cursor()
- if id is None:
- c.execute('SELECT %s.NEXTVAL FROM DUAL' % (self.createSequenceName(ta=
ble)))
- id =3D c.fetchone()[0]
- names =3D [idName] + names
- values =3D [id] + values
- q =3D self._insertSQL(table, names, values)
- if self.debug:
- self.printDebug(conn, q, 'QueryIns')
- c.execute(q)
- if self.debugOutput:
- self.printDebug(conn, id, 'QueryIns', 'result')
- return id
-=09
- def sqlAddLimit(self,query,limit):
- sql =3D query
- sql =3D sql.replace("SELECT","SELECT ROWNO, ")
- if sql.find('WHERE') !=3D -1:
- sql =3D sql + ' AND ' + limit
- else:=09
- sql =3D sql + 'WHERE ' + limit
-
- return sql
- =09
- def _queryAddLimitOffset(self, query, start, end):
- if start: raise LowerBoundOfSliceIsNotSupported
- limit =3D ' ROWNO <=3D %d ' % (end)
- return self.sqlAddLimit(query,limit)
-
- =20
- def createTable(self, soClass):
- #we create the table in a transaction because the addition of the
- #table and the sequence must be atomic=20
-
- #i tried to use the transaction class but i get a recursion limi=
t error =20
- # t=3Dself.transaction()
- # t.query('CREATE TABLE %s (\n%s\n)' % \
- # (soClass._table, self.createColumns(soClass)))
- # =09
- # t.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._ta=
ble))
- # t.commit()
- =09
- #so use transaction when the problem will be solved
- self.query('CREATE TABLE %s (\n%s\n)' % \
- (soClass._table, self.createColumns(soClass)))
- self.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._tab=
le))
-=20
-=09
- def createColumn(self, soClass, col):
- return col.maxdbCreateSQL()
-=09
- def createIDColumn(self, soClass):
- return '%s INT PRIMARY KEY' % soClass._idName
-=09
- def dropTable(self, tableName,cascade=3DFalse):
- #we drop the table in a transaction because the removal of the
- #table and the sequence must be atomic=20
- #i tried to use the transaction class but i get a recursion limit erro=
r=09
- # try:
- # t=3Dself.transaction()
- # t.query("DROP TABLE %s" % tableName)
- # t.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
- # t.commit()
- # except:t.rollback()
- #so use transaction when the problem will be solved
- self.query("DROP TABLE %s" % tableName)
- self.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
-=09
- def joinSQLType(self, join):
- return 'INT NOT NULL'
-=09
- def tableExists(self, tableName):
- for (table,) in self.queryAll("SELECT OBJECT_NAME FROM ALL_OBJECTS WHE=
RE OBJECT_TYPE=3D'TABLE'"):
- if table.lower() =3D=3D tableName.lower():
- return True
- return False
- =20
-=09
- def addColumn(self, tableName, column):
- self.query('ALTER TABLE %s ADD %s' %
- (tableName,
- column.maxdbCreateSQL()))
-=09
- def delColumn(self, tableName, column):
- self.query('ALTER TABLE %s DROP COLUMN %s' %
- (tableName,
- column.dbName))
-=09
-
-
-
- GET_COLUMNS =3D (" SELECT COLUMN_NAME,NULLABLE,DATA_DEFAULT,DATA_TYPE=
, DATA_LENGTH,DATA_SCALE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=3DUPPER('=
%s')")
- GET_PK_AND_FK =3D (""" SELECT constraint_cols .column_name,constraints.=
constraint_type , refname,reftablename FROM
- user_cons_columns constraint_cols=20
- INNER JOIN user_constraints constraints ON constraint_cols.cons=
traint_name=3Dconstraints.constraint_name=20
- LEFT OUTER JOIN show_foreign_key fk on constraint_cols.column_nam=
e=3Dfk.columnname
- WHERE constraints.table_name =3DUPPER('%s')"""
- )
-=09
- def columnsFromSchema(self, tableName, soClass):
- colData =3D self.queryAll(self.GET_COLUMNS
- % tableName)
- =09
- results =3D []
- keymap =3D {}
- pkmap=3D{}
- fkData =3D self.queryAll(self.GET_PK_AND_FK% tableName)
- for col, cons_type, refcol, reftable in fkData:
- col_name=3D col.lower()
- pkmap[col_name]=3DFalse
- if cons_type =3D=3D 'R':
- keymap[col_name]=3Dreftable.lower()
- =09
- elif cons_type =3D=3D 'P':
- pkmap[col_name]=3DTrue
- =09
- if len(pkmap) =3D=3D 0: raise PrimaryKeyNotFounded, tableName
- =09
- for field, nullAllowed, default, data_type, data_len, data_scale in co=
lData:
- #id is defined as primary key --> ok
- #We let sqlobject raise error if the 'id' is used for another column
- field_name =3D field.lower()=20
- if field_name =3D=3D 'id' and pkmap[field_name]:
- continue
- =09
- colClass, kw =3D self.guessClass(data_type,data_len,data_scale)
- kw['name'] =3D field_name
- =09
- if nullAllowed =3D=3D 'Y' :=20
- nullAllowed=3DFalse
- else:
- nullAllowed=3DTrue
- =09
- kw['notNone'] =3D nullAllowed
- if default is not None:
- kw['default'] =3D default
- =09
- if keymap.has_key(field_name):
- kw['foreignKey'] =3D keymap[field_name]
- =09
- results.append(colClass(**kw))
- =20
- return results
- =20
- _numericTypes=3D['INTEGER', 'INT','SMALLINT']
- _dateTypes=3D['DATE','TIME','TIMESTAMP']
-=09
- def guessClass(self, t, flength, fscale=3DNone):
- """
- An internal method that tries to figure out what Col subclass
- is appropriate given whatever introspective information is
- available -- both very database-specific.
- """
- if t in self._numericTypes:
- return col.IntCol, {}
- # The type returned by the sapdb library for LONG is SapDB_LongReader
- #To get the data call the read member with desired size (default =3D-1=
means get all)
- =09
- elif t.find('LONG') !=3D -1:
- return col.StringCol, {'length': flength,
- 'varchar': False}
- elif t in self._dateTypes:
- return col.DateTimeCol, {}
- elif t =3D=3D 'FIXED':
- return CurrencyCol,{'size':flength,
- 'precision':fscale}
- else:
- return col.Col, {}
\ No newline at end of file
|
|
From: <sub...@co...> - 2004-06-14 11:54:39
|
Author: ahmedmo Date: 2004-06-14 03:52:01 -0400 (Mon, 14 Jun 2004) New Revision: 129 Removed: trunk/SQLObject/maxdbconnection.pyc Log: Removed file/folder Deleted: trunk/SQLObject/maxdbconnection.pyc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (Binary files differ) |
|
From: <sub...@co...> - 2004-06-14 11:53:51
|
Author: ahmedmo Date: 2004-06-14 03:51:16 -0400 (Mon, 14 Jun 2004) New Revision: 128 Added: trunk/SQLObject/maxdb/ Log: Created folder remotely |
|
From: <sub...@co...> - 2004-06-14 11:52:59
|
Author: ahmedmo
Date: 2004-06-14 03:50:22 -0400 (Mon, 14 Jun 2004)
New Revision: 127
Added:
trunk/SQLObject/__init__.py
trunk/SQLObject/__init__.pyc
trunk/SQLObject/maxdbconnection.py
trunk/SQLObject/maxdbconnection.pyc
Log:
Initial Import
Added: trunk/SQLObject/__init__.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/__init__.py 2004-06-08 13:37:05 UTC (rev 126)
+++ trunk/SQLObject/__init__.py 2004-06-14 07:50:22 UTC (rev 127)
@@ -0,0 +1,14 @@
+from sqlobject.dbconnection import registerConnection
+
+def builder():
+ import maxdbconnection
+ return maxdbconnection.MaxdbConnection
+
+def isSupported():
+ try:
+ import sapdb
+ except ImportError:
+ return False
+ return False
+
+registerConnection(['maxdb','sapdb'],builder, isSupported)
Added: trunk/SQLObject/__init__.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/__init__.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/SQLObject/maxdbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/maxdbconnection.py 2004-06-08 13:37:05 UTC (rev 126)
+++ trunk/SQLObject/maxdbconnection.py 2004-06-14 07:50:22 UTC (rev 127)
@@ -0,0 +1,276 @@
+"""
+Contributed by Edigram SAS,Paris=20
+Ahmed MOHAMED ALI <ahm...@ya...> 27 April 2004
+This program 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.
+
+connection creation sample=20
+__connection__ =3D DBConnection.maxdbConnection(
+ host=3Dhostname, database=3Ddbname,
+ user=3Duser_name, password=3Duser_password,autoCommit=3D1,debug=3D1)
+"""
+from sqlobject.dbconnection import DBAPI
+from sqlobject import col
+dbapi =3D None
+
+
+
+class maxdbException(Exception):
+ def __init__(self, value):
+ self.value =3D value
+ def __str__(self):
+ return repr(self.value)
+=09
+class LowerBoundOfSliceIsNotSupported(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'')
+=09
+
+class IncorrectIDStyleError(maxdbException) :
+ def __init__(self,value):
+ maxdbException.__init__(self,'This primary key name is not in the exp=
ected style,please rename the column to %s or switch to another style'%(v=
alue))
+
+class StyleMismatchError(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,'The name %s is only permitted for primar=
y key,change the column name or switch to another style'%value)
+
+
+class PrimaryKeyNotFounded(maxdbException):
+ def __init__(self, value):
+ maxdbException.__init__(self,"No primary key was defined on table %s"%=
(value))
+
+ =09
+SAPDBMAX_ID_LENGTH=3D32 =20
+ =09
+class MaxdbConnection(DBAPI):
+
+ =20
+ supportTransactions =3D True
+ dbName =3D 'maxdb'
+ schemes =3D [dbName]
+ =20
+ def __init__ (self, user, password, database, host =3D '',autoCommit=3D=
1,sqlmode=3D'internal',isolation=3DNone,timeout=3DNone, **kw):
+ global dbapi
+ if dbapi is None:
+ from sapdb import dbapi
+ self.autoCommit =3D autoCommit
+ self.user =3D user
+ self.password =3D password
+ self.database =3D database
+ self.host =3D host
+ self.sqlmode =3D sqlmode
+ self.isolation =3D isolation
+ self.timeout =3D timeout
+ =20
+ DBAPI.__init__(self, **kw)
+ =20
+ def connectionFromURI(cls, uri):
+ auth, password, host, path, args =3D cls._parseURI(uri)
+ path =3D path.replace('/', os.path.sep)
+ return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **args)
+ connectionFromURI =3D classmethod(connectionFromURI)
+=09
+ =09
+ def _getConfigParams(self,sqlmode,auto):
+ autocommit=3D'off'
+ if auto:autocommit=3D'on'
+ opt=3D{}
+ opt["autocommit"]=3Dautocommit
+ opt["sqlmode"]=3Dsqlmode
+ if self.isolation:
+ opt["isolation"]=3Dself.isolation
+ if self.timeout :
+ opt["timeout"]=3Dself.timeout
+ =09
+ return opt
+ =09
+ def _setAutoCommit(self, conn, auto):
+ conn.close()
+ conn.__init__(self.user, self.password, self.database, self.host,**sel=
f._getConfigParams(self.sqlmode,auto))
+ =09
+ =20
+=09
+ =20
+ def createSequenceName(self,table):
+ """ sequence name are builded with the concatenation of the table name=
with '_SEQ' word
+ we truncate the name of the sequence_name because
+ sapdb identifier cannot exceed 32 characters
+ so that the name of the sequence does not exceed 32 characters
+ """
+ return '%s_SEQ'%(table[:SAPDBMAX_ID_LENGTH -4])
+=09
+ def makeConnection(self):
+ conn =3D dbapi.Connection(self.user, self.password, self.database, se=
lf.host,**self._getConfigParams(self.sqlmode,self.autoCommit) )
+ return conn
+=09
+ def _queryInsertID(self, conn, table, idName, id, names, values):
+ c =3D conn.cursor()
+ if id is None:
+ c.execute('SELECT %s.NEXTVAL FROM DUAL' % (self.createSequenceName(ta=
ble)))
+ id =3D c.fetchone()[0]
+ names =3D [idName] + names
+ values =3D [id] + values
+ q =3D self._insertSQL(table, names, values)
+ if self.debug:
+ self.printDebug(conn, q, 'QueryIns')
+ c.execute(q)
+ if self.debugOutput:
+ self.printDebug(conn, id, 'QueryIns', 'result')
+ return id
+=09
+ def sqlAddLimit(self,query,limit):
+ sql =3D query
+ sql =3D sql.replace("SELECT","SELECT ROWNO, ")
+ if sql.find('WHERE') !=3D -1:
+ sql =3D sql + ' AND ' + limit
+ else:=09
+ sql =3D sql + 'WHERE ' + limit
+
+ return sql
+ =09
+ def _queryAddLimitOffset(self, query, start, end):
+ if start: raise LowerBoundOfSliceIsNotSupported
+ limit =3D ' ROWNO <=3D %d ' % (end)
+ return self.sqlAddLimit(query,limit)
+
+ =20
+ def createTable(self, soClass):
+ #we create the table in a transaction because the addition of the
+ #table and the sequence must be atomic=20
+
+ #i tried to use the transaction class but i get a recursion limi=
t error =20
+ # t=3Dself.transaction()
+ # t.query('CREATE TABLE %s (\n%s\n)' % \
+ # (soClass._table, self.createColumns(soClass)))
+ # =09
+ # t.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._ta=
ble))
+ # t.commit()
+ =09
+ #so use transaction when the problem will be solved
+ self.query('CREATE TABLE %s (\n%s\n)' % \
+ (soClass._table, self.createColumns(soClass)))
+ self.query("CREATE SEQUENCE %s" % self.createSequenceName(soClass._tab=
le))
+=20
+=09
+ def createColumn(self, soClass, col):
+ return col.maxdbCreateSQL()
+=09
+ def createIDColumn(self, soClass):
+ return '%s INT PRIMARY KEY' % soClass._idName
+=09
+ def dropTable(self, tableName,cascade=3DFalse):
+ #we drop the table in a transaction because the removal of the
+ #table and the sequence must be atomic=20
+ #i tried to use the transaction class but i get a recursion limit erro=
r=09
+ # try:
+ # t=3Dself.transaction()
+ # t.query("DROP TABLE %s" % tableName)
+ # t.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+ # t.commit()
+ # except:t.rollback()
+ #so use transaction when the problem will be solved
+ self.query("DROP TABLE %s" % tableName)
+ self.query("DROP SEQUENCE %s" % self.createSequenceName(tableName))
+=09
+ def joinSQLType(self, join):
+ return 'INT NOT NULL'
+=09
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll("SELECT OBJECT_NAME FROM ALL_OBJECTS WHE=
RE OBJECT_TYPE=3D'TABLE'"):
+ if table.lower() =3D=3D tableName.lower():
+ return True
+ return False
+ =20
+=09
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD %s' %
+ (tableName,
+ column.maxdbCreateSQL()))
+=09
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+=09
+
+
+
+ GET_COLUMNS =3D (" SELECT COLUMN_NAME,NULLABLE,DATA_DEFAULT,DATA_TYPE=
, DATA_LENGTH,DATA_SCALE FROM USER_TAB_COLUMNS WHERE TABLE_NAME=3DUPPER('=
%s')")
+ GET_PK_AND_FK =3D (""" SELECT constraint_cols .column_name,constraints.=
constraint_type , refname,reftablename FROM
+ user_cons_columns constraint_cols=20
+ INNER JOIN user_constraints constraints ON constraint_cols.cons=
traint_name=3Dconstraints.constraint_name=20
+ LEFT OUTER JOIN show_foreign_key fk on constraint_cols.column_nam=
e=3Dfk.columnname
+ WHERE constraints.table_name =3DUPPER('%s')"""
+ )
+=09
+ def columnsFromSchema(self, tableName, soClass):
+ colData =3D self.queryAll(self.GET_COLUMNS
+ % tableName)
+ =09
+ results =3D []
+ keymap =3D {}
+ pkmap=3D{}
+ fkData =3D self.queryAll(self.GET_PK_AND_FK% tableName)
+ for col, cons_type, refcol, reftable in fkData:
+ col_name=3D col.lower()
+ pkmap[col_name]=3DFalse
+ if cons_type =3D=3D 'R':
+ keymap[col_name]=3Dreftable.lower()
+ =09
+ elif cons_type =3D=3D 'P':
+ pkmap[col_name]=3DTrue
+ =09
+ if len(pkmap) =3D=3D 0: raise PrimaryKeyNotFounded, tableName
+ =09
+ for field, nullAllowed, default, data_type, data_len, data_scale in co=
lData:
+ #id is defined as primary key --> ok
+ #We let sqlobject raise error if the 'id' is used for another column
+ field_name =3D field.lower()=20
+ if field_name =3D=3D 'id' and pkmap[field_name]:
+ continue
+ =09
+ colClass, kw =3D self.guessClass(data_type,data_len,data_scale)
+ kw['name'] =3D field_name
+ =09
+ if nullAllowed =3D=3D 'Y' :=20
+ nullAllowed=3DFalse
+ else:
+ nullAllowed=3DTrue
+ =09
+ kw['notNone'] =3D nullAllowed
+ if default is not None:
+ kw['default'] =3D default
+ =09
+ if keymap.has_key(field_name):
+ kw['foreignKey'] =3D keymap[field_name]
+ =09
+ results.append(colClass(**kw))
+ =20
+ return results
+ =20
+ _numericTypes=3D['INTEGER', 'INT','SMALLINT']
+ _dateTypes=3D['DATE','TIME','TIMESTAMP']
+=09
+ def guessClass(self, t, flength, fscale=3DNone):
+ """
+ An internal method that tries to figure out what Col subclass
+ is appropriate given whatever introspective information is
+ available -- both very database-specific.
+ """
+ if t in self._numericTypes:
+ return col.IntCol, {}
+ # The type returned by the sapdb library for LONG is SapDB_LongReader
+ #To get the data call the read member with desired size (default =3D-1=
means get all)
+ =09
+ elif t.find('LONG') !=3D -1:
+ return col.StringCol, {'length': flength,
+ 'varchar': False}
+ elif t in self._dateTypes:
+ return col.DateTimeCol, {}
+ elif t =3D=3D 'FIXED':
+ return CurrencyCol,{'size':flength,
+ 'precision':fscale}
+ else:
+ return col.Col, {}
\ No newline at end of file
Added: trunk/SQLObject/maxdbconnection.pyc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(Binary files differ)
Property changes on: trunk/SQLObject/maxdbconnection.pyc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
|
|
From: <sub...@co...> - 2004-06-08 17:39:07
|
Author: ianb
Date: 2004-06-08 09:37:05 -0400 (Tue, 08 Jun 2004)
New Revision: 126
Modified:
trunk/SQLObject/sqlobject/main.py
Log:
Removed debugging print statement
Modified: trunk/SQLObject/sqlobject/main.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/main.py 2004-06-08 13:36:41 UTC (rev 125)
+++ trunk/SQLObject/sqlobject/main.py 2004-06-08 13:37:05 UTC (rev 126)
@@ -1095,7 +1095,7 @@
orderBy =3D map(self._mungeOrderBy, orderBy)
else:
orderBy =3D self._mungeOrderBy(orderBy)
- print "OUT: %r; in: %r" % (sourceClass.sqlrepr(orderBy), sourceC=
lass.sqlrepr(self.ops['orderBy']))
+ #print "OUT: %r; in: %r" % (sourceClass.sqlrepr(orderBy), source=
Class.sqlrepr(self.ops['orderBy']))
self.ops['dbOrderBy'] =3D orderBy
if ops.has_key('connection') and ops['connection'] is None:
del ops['connection']
|
|
From: <sub...@co...> - 2004-06-08 17:38:42
|
Author: ianb
Date: 2004-06-08 09:36:41 -0400 (Tue, 08 Jun 2004)
New Revision: 125
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Deal with empty values (that int() still looks suspicious to me)
Modified: trunk/SQLObject/sqlobject/col.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/col.py 2004-06-08 13:36:01 UTC (rev 124)
+++ trunk/SQLObject/sqlobject/col.py 2004-06-08 13:36:41 UTC (rev 125)
@@ -329,10 +329,10 @@
return sqlbuilder.FALSE
=20
def toPython(self, value, state):
- if int(value):
+ if not value or not int(value):
+ return sqlbuilder.FALSE
+ else:
return sqlbuilder.TRUE
- else:
- return sqlbuilder.FALSE
=20
class SOBoolCol(SOCol):
=20
|
|
From: <sub...@co...> - 2004-06-08 17:38:02
|
Author: ianb
Date: 2004-06-08 09:36:01 -0400 (Tue, 08 Jun 2004)
New Revision: 124
Modified:
trunk/SQLObject/sqlobject/dbconnection.py
Log:
Fixed bug in .selectBy() with multiple keyword arguments
Modified: trunk/SQLObject/sqlobject/dbconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/dbconnection.py 2004-06-08 13:35:36 UTC (re=
v 123)
+++ trunk/SQLObject/sqlobject/dbconnection.py 2004-06-08 13:36:01 UTC (re=
v 124)
@@ -413,7 +413,7 @@
self.sqlrepr(secondValue)))
=20
def _SO_columnClause(self, soClass, kw):
- return ' '.join(['%s =3D %s' %
+ return ' AND '.join(['%s =3D %s' %
(soClass._SO_columnDict[key].dbName,
self.sqlrepr(value))
for key, value
|
|
From: <sub...@co...> - 2004-06-08 17:37:38
|
Author: ianb
Date: 2004-06-08 09:35:36 -0400 (Tue, 08 Jun 2004)
New Revision: 123
Modified:
trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
Log:
Backward compatibility
Modified: trunk/SQLObject/sqlobject/firebird/firebirdconnection.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-05-30 1=
4:45:36 UTC (rev 122)
+++ trunk/SQLObject/sqlobject/firebird/firebirdconnection.py 2004-06-08 1=
3:35:36 UTC (rev 123)
@@ -34,7 +34,7 @@
password =3D 'masterkey'
if not auth:
auth=3D'sysdba'
- path =3D path.replace('/', os.path.sep)
+ path =3D path.replace('/', os.sep)
return cls(host, db=3Dpath, user=3Dauth, passwd=3Dpassword, **ar=
gs)
connectionFromURI =3D classmethod(connectionFromURI)
=20
|
|
From: <sub...@co...> - 2004-05-27 10:04:39
|
Author: ahmedmo Date: 2004-05-27 02:03:49 -0400 (Thu, 27 May 2004) New Revision: 121 Removed: trunk/SQLObject/conf/ Log: Removed file/folder created by error by the client tool |
|
From: <sub...@co...> - 2004-05-27 10:04:28
|
Author: ahmedmo Date: 2004-05-27 02:03:38 -0400 (Thu, 27 May 2004) New Revision: 120 Removed: trunk/SQLObject/dav/ Log: Removed file/folder created by error by the client tool |