seth wrote:
> Hi Mike,
>
> Thank you very much for replying to my post. I really appreciate it.
>
> I agree that the init of the classes may have something to do with the
> problem.
> Maybe the way we are defining the attributes does not allow to
> SQLAlchemy table
> wrappers to view the attributes' values?

hi Seth -

to be honest, I withheld saying anything earlier, but the very java-esque
style of code you have here is really not helping the performance of your
application or its readability.    In Python, using explicit setters and
getters for all instance variables is unnecessary and adds palpable
overhead - since Python's method dispatch is nowheres near as efficient as
that of Java's. The famous rant on this topic is here: 
http://dirtsimple.org/2004/12/python-is-not-java.html  Also, the __name
style of naming, while it is part of pep8 and all, is becoming less and
less common these days as the implicit name mangling of the Python
interpreter leads to confusing results.

I don't see your mappings here but if in fact you're trying to map to
__name style attributes, its unlikely to work properly since SQLA doesn't
take into account the name mangling inherent in the usage of such names.  
It is a likely candidate for the issue you're having.








>
> What confuses me the most is that I am actually able to insert a row
> using
> sprint-python with the addxLPRVariable function  below.
> Both approaches use the same variable classes.
>
> The row with id=33 below was inserted using spring-python.
> The row with id=32 below was inserted using SQLAlchemy.
>
>
>
> mysql> select * from variables where id >=32;
> +----------------------+-------+-------+----------+-----------
> +----------------------+
> | id                   | value | units | name     | dependent |
> independent_variable |
> +----------------------+-------+-------+----------+-----------
> +----------------------+
> | 00000000000000000032 |     1 |       |          |      NULL
> |                 NULL |
> | 00000000000000000033 |     1 | Hz    | variable |         0
> |                 NULL |
> +----------------------+-------+-------+----------+-----------
> +----------------------+
> 2 rows in set (0.00 sec)
>
>
> #----------------------------------------------------------------------------------------------
> #
>
> This function writes to the database:
>
> #----------------------------------------------------------------------------------------------
> #
>
>
>
>
>     def addxLPRVariable( self, xLPRVariable ):
>
>         """Add an xLPRVariable to the database."""
>         rowsAffected=self.database_template.execute( """
>             INSERT INTO variables
>             (id, name, units, value, dependent)
>             VALUES
>             (null, ?, ?, ?, ?)
>             """, ( xLPRVariable.getName(), xLPRVariable.getUnits(),
> xLPRVariable.getValue(), xLPRVariable.isDependent() ) )
>         self.connection_factory.commit()
>         logger.debug( "Added %d rows"%rowsAffected )
>         print "Added %d"%rowsAffected
>         return rowsAffected
>
>
> #----------------------------------------------------------------------------------------------
> #
>
> Here are the sql scripts
>
> #----------------------------------------------------------------------------------------------
> #
>
>
> create table variables
> (
>   id bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT
> 'Primary key, sequence',
>   value float NOT NULL COMMENT 'Initial value for variable',
>   units varchar(45) NOT NULL COMMENT 'Common Si units of variable',
>   name varchar(45) NOT NULL COMMENT 'Name of the variable',
>   dependent boolean,
>   independent_variable float COMMENT 'The independent variable x',
>   PRIMARY KEY (id)
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1  COMMENT='Maps to the
> xLPRVariable Object';
>
> create table dependence_variables
> (
>   id bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT
> 'Primary key, sequence',
>   variable_id bigint(20) unsigned zerofill COMMENT 'Foreign key to
> dependency_variable table',
>   interpolate boolean,
>   dependent_function varchar(4000) COMMENT 'The dependent function',
>   evaluate boolean,
>   xname_units varchar(45),
>   xname varchar(45),
>   PRIMARY KEY (id),
>   FOREIGN KEY (variable_id) REFERENCES variables(id)
>       ON DELETE CASCADE
>       ON UPDATE CASCADE
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1  COMMENT='Maps to the
> dependency_variable object attribute';
>
> create table data_set
> (
>   id bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT
> 'Primary key, sequence',
>   dependence_variable_id bigint(20) unsigned zerofill NOT NULL
> COMMENT 'data_set will be grouped by data_set_ids',
>   x float  NOT NULL COMMENT 'Value of x',
>   y float  NOT NULL COMMENT 'Value of y',
>   PRIMARY KEY (id),
>   FOREIGN KEY (dependence_variable_id) REFERENCES dependence_variables
> (id)
>       ON DELETE CASCADE
>       ON UPDATE CASCADE
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1  COMMENT='Maps to the
> dependency_variable.data_set attribute';
>
> #----------------------------------------------------------------------------------------------
> #
>
> Here are the classes definition
>
> #----------------------------------------------------------------------------------------------
> #
> class xLPRVariable( VariableQuantity ):
>     '''
>     Defines a VariableUnitsAware object that may be a function of
> another
>     independent variable x which is also a units-aware object
>
>     classdocs
>
>         args[0] = value:float
>         args[1] = units:str
>
>         kwargs['name'] = name:str
>         kwargs['dependenceVariable'] =
> dependenceVariable:DependenceVariable
>
>     '''
>
>     def __init__( self, *args, **kwargs ):
>
>         '''
>         Constructor positional/required arguments:
>         value:float = initial value for variable
>         units:String = common SI units of variable
>
>         Constructor keyed/optional arguments:
>         name:String = name of variable
>         dependent:Boolean is variable dependent upon another SIAM
> variable
>         dependenceVariable:DependenceVariable
>
>         '''
>
>
> #=======================================================================
>         # call the bound version of the superclass constructor
>
> #=======================================================================
>         super( xLPRVariable, self ).__init__( *args )
>         print args
>         if kwargs.has_key( 'name' ):
>             self.__name=kwargs['name']
>         else:
>             self.__name='variable'
>             self.setName('variable')
>
>         if kwargs.has_key( 'dependenceVariable' ):
>             self.__dependenceVariable=kwargs['dependenceVariable']
>         else:
>             self.__dependenceVariable=None
>
>         if self.__dependenceVariable is not None:
>             self.__dependent=True
>         else:
>             self.__dependent=False
>
>         #set the units
>         if kwargs.has_key( 'units' ):
>             self.setUnits(kwargs['units'])
>         else:
>             self.setUnits(args[1])
>
> #===============================================================================
> #                 __name: String
> #===============================================================================
>     def getName( self ):
>         '''
>         get VariableUnitsAware name
>         @param name: VariableUnitsAware name
>         @type name: String
>         '''
>         return self.__name
>
>     def setName( self, name ):
>         '''
>         set VariableUnitsAware name
>         @param name: VariableUnitsAware name
>         @type name: String
>         '''
>         self.__name=name
>
>     def delName( self ):
>         '''
>         delete VariableUnitsAware name
>         @param name: VariableUnitsAware name
>         @type name: String
>         '''
>         del self.__name
>
>
> #===============================================================================
> #                 units: String
> #===============================================================================
>     def getUnits( self ):
>         '''
>         Units:String = units of VariableUnitsAware object
>         '''
>         return self._getVariableUnits()
>
>     def _getVariableUnits( self ):
>         '''
>         Units:String = units of VariableUnitsAware object
>         '''
>         return self.getUnitName()
>
>     def setUnits( self, units ):
>         '''
>         Units:String = units of VariableUnitsAware object
>         '''
>         self._setVariableUnits( units )
>
>
>     def _setVariableUnits( self, units ):
>         '''
>         Units:String = units of VariableUnitsAware object
>         '''
>         self.convertToUnit( units )
>
>
>     def delUnits( self ):
>         pass
>
> #===============================================================================
> #                 x: float
> #===============================================================================
>
>     def __getDependentValue( self, x ):
>         '''
>         evaluate y=f(x) by interpolation or by dependence function y=f
> (x)
>         @param x: independent variable
>         @type x: float
>         '''
>         return self.value
>
>
>     def getValueX( self, x = None ):
>         '''
>         retrieve constant value or evaluate by providing a value for x
>         @param x: value of independent variable to be evaluated
>         @type x: float
>         '''
>         if x is not None:
>             if self.__dependent:
>                 if self.__dependenceVariable.isInterpolated():
>                     return self.__dependenceVariable.interpolate( x )
>                 elif self.__dependenceVariable.isEvaluated():
>                     return self.__dependenceVariable.evaluate( x )
>             else:
>                 raise xLPRVariableException, "xLPRVariable: Dependence
> is not defined!"
>         else:
>             return self.value
>
>     def isDependent( self ):
>         '''
>         Check for dependence; returns True or False
>         '''
>         if self.__dependent:
>             return True
>         else:
>             return False
>
>     def getDependenceVariable( self ):
>         '''
>         Retrieve DependenceVariable object
>         '''
>         return self.__dependenceVariable
>
>
>     def setDependenceVariable( self, dependenceVariable ):
>         '''
>         Establish a dependence between another variable
>         @param dependenceVariable: variable that this
> VariableUnitsAware object is dependent on
>         @type dependenceVariable: DependenceVariable
>         '''
>         self.__dependenceVariable=dependenceVariable
>         self.__dependent=True
>
> #===============================================================================
> #      create properties using Python 'property' function
> #===============================================================================
>     name=property( getName, setName, delName, "Variable Name's
> Docstring" )
>     units=property( getUnits, setUnits, delUnits, "Variable Units's
> Docstring" )
>
>
>
>
> class DependenceVariable( VariableQuantity ):
>     '''
>     classdocs
>     '''
>
>     def __init__( self, *args, **kwargs ):
> #    def __init__( self, xnameUnits, xname, dataSet = None,
> dependentFunction = None ):
>         '''
>         Constructor positional/required arguments:
>         xname:String giving name of independent variable
>         xnameUnits:String giving name of units for independent
> variable
>
>         Constructor keyed/optional arguments:
>         dataSet = list of tuples of (x,y) pairs
>         dependentFunction = single-valued univariate function where y
> = f(x)
>         '''
>
>         if len( args )<2:
>             raise DependenceException, "Error: expecting 2 values in
> *args list"
>
>         args2=[]
>         args2.append( 1.0 )
>         args2.append( args[0] )
>
>         # call the bound version of the superclass constructor
>         super( DependenceVariable, self ).__init__( *args2 )
>
>         if kwargs.has_key( 'dataSet' ):
>             self.__dataSet=kwargs['dataSet']
>         else:
>             self.__dataSet=None
>
>         if kwargs.has_key( 'dependentFunction' ):
>             self.__dependentFunction=kwargs['dependentFunction']
>         else:
>             self.__dependentFunction=None
>
>
>         if self.__dataSet is None and self.__dependentFunction is
> None:
>             raise DependenceException, "Warning: dependence not
> defined"
>
>         if isinstance( args[0], str ):
>             self.__xname=args[0]
>         else:
>             raise DependenceException, "Error: args[0] = xname wrong
> type"
>
>         if isinstance( args[1], str ):
>             self.__xnameUnits=args[1]
>         else:
>             raise DependenceException, "Error: args[1] = xnameUnits
> wrong type"
>
>
>         self.x=[]
>         self.y=[]
>         self.vi=None
>
>         if self.__dataSet is not None:
>
> #===================================================================
>             # create InterpolatingFunction object from Scientific
> Python package
>
> #===================================================================
>             for x, y in self.__dataSet:
>                 self.x.append( x )
>                 self.y.append( y )
>
>             self.x=np.asarray( self.x )
>             self.y=np.asarray( self.y )
>             self.vi=Ip( ( self.x, ), self.y )
>
>             self.__interpolate=True
>
>         else:
>             self.__dataSet=None
>             self.__interpolate=False
>
>         if self.__dependentFunction is not None:
>             self.__evaluate=True
>         else:
>             self.__dependentFunction=None
>             self.__evaluate=False
>
>         #self.__id;
>
>     def isInterpolated( self ):
>         return self.__interpolate
>
>     def isEvaluated( self ):
>         return self.__evaluate
>
>     def getXnameUnits( self ):
>         '''
>         units:String of independent variable
>         '''
>         return self.getUnitName()
>
>     def getXname( self ):
>         '''
>         name:String of independent variable
>         '''
>         return self.__xname
>
>     def getData( self ):
>         '''
>         dependence data as list of tuples that are ordered pairs (x,y)
>         '''
>         if self.__dataSet is not None:
>             return self.__dataSet
>         else:
>             raise DependenceException, "Error: Dependence Dataset not
> defined"
>
>     def getFunction( self ):
>         '''
>         f(x) dependence function of single independent variable x: y=f
> (x)
>         '''
>         if self.__dependentFunction is not None:
>             return self.__dependentFunction
>         else:
>             raise DependenceException, "Error: Dependence function not
> defined"
>
>     def setData( self, data ):
>         '''
>         set dependence data as list of tuples that are ordered pairs
> (x,y)
>         @param data: list of ordered pairs of (independent,dependent)
>         @type data: list of tuples (x,y)
>         '''
>         self.__dataSet=data
>         self.__interpolate=True
>
> #===================================================================
>         # create InterpolatingFunction object from Scientific Python
> package
>
> #===================================================================
>         for x, y in self.__dataSet:
>             self.x.append( x )
>             self.y.append( y )
>
>         self.x=np.asarray( self.x )
>         self.y=np.asarray( self.y )
>         self.vi=Ip( ( self.x, ), self.y )
>
>     def setFunction( self, function ):
>         '''
>         Set dependent function
>         @param function: y = f(x)
>         @type function: f(x)
>         '''
>         self.__dependentFunction=function
>         self.__evaluate=True
>
>     def interpolate( self, x ):
>         if self.__interpolate:
>             return self.vi( x )
>         else:
>             raise DependenceException, "Error: dependence data not
> defined"
>
>     def evaluate( self, x ):
>         '''
>         Evaluate using supplied univariate function (see setFunction)
>         @param x: independent variable
>         @type x: float
>         '''
>         if self.__dependentFunction is None:
>             raise DependenceException, "Error: Dependent function has
> not been specified"
>         else:
>             return self.__dependentFunction( x )
>
>
>
> class DataSet( object ):
>     '''
>     classdocs
>     '''
>     def __init__( self, x, y):
>         self.x=x
>         self.y=y
>
>
>     def getX(self):
>         return self.__x
>
>
>     def getY(self):
>         return self.__y
>
>
>     def setX(self, value):
>         self.__x = value
>
>
>     def setY(self, value):
>         self.__y = value
>
>
>     def delX(self):
>         del self.__x
>
>
>     def delY(self):
>         del self.__y
>
>     x = property(getX, setX, delX, "X's Docstring")
>
>     y = property(getY, setY, delY, "Y's Docstring")
>
>
>
> class DependenceVariable( VariableQuantity ):
>     '''
>     classdocs
>     '''
>
>     def __init__( self, *args, **kwargs ):
> #    def __init__( self, xnameUnits, xname, dataSet = None,
> dependentFunction = None ):
>         '''
>         Constructor positional/required arguments:
>         xname:String giving name of independent variable
>         xnameUnits:String giving name of units for independent
> variable
>
>         Constructor keyed/optional arguments:
>         dataSet = list of tuples of (x,y) pairs
>         dependentFunction = single-valued univariate function where y
> = f(x)
>         '''
>
>         if len( args )<2:
>             raise DependenceException, "Error: expecting 2 values in
> *args list"
>
>         args2=[]
>         args2.append( 1.0 )
>         args2.append( args[0] )
>
>         # call the bound version of the superclass constructor
>         super( DependenceVariable, self ).__init__( *args2 )
>
>         if kwargs.has_key( 'dataSet' ):
>             self.__dataSet=kwargs['dataSet']
>         else:
>             self.__dataSet=None
>
>         if kwargs.has_key( 'dependentFunction' ):
>             self.__dependentFunction=kwargs['dependentFunction']
>         else:
>             self.__dependentFunction=None
>
>
>         if self.__dataSet is None and self.__dependentFunction is
> None:
>             raise DependenceException, "Warning: dependence not
> defined"
>
>         if isinstance( args[0], str ):
>             self.__xname=args[0]
>         else:
>             raise DependenceException, "Error: args[0] = xname wrong
> type"
>
>         if isinstance( args[1], str ):
>             self.__xnameUnits=args[1]
>         else:
>             raise DependenceException, "Error: args[1] = xnameUnits
> wrong type"
>
>
>         self.x=[]
>         self.y=[]
>         self.vi=None
>
>         if self.__dataSet is not None:
>
> #===================================================================
>             # create InterpolatingFunction object from Scientific
> Python package
>
> #===================================================================
>             for x, y in self.__dataSet:
>                 self.x.append( x )
>                 self.y.append( y )
>
>             self.x=np.asarray( self.x )
>             self.y=np.asarray( self.y )
>             self.vi=Ip( ( self.x, ), self.y )
>
>             self.__interpolate=True
>
>         else:
>             self.__dataSet=None
>             self.__interpolate=False
>
>         if self.__dependentFunction is not None:
>             self.__evaluate=True
>         else:
>             self.__dependentFunction=None
>             self.__evaluate=False
>
>         #self.__id;
>
>     def isInterpolated( self ):
>         return self.__interpolate
>
>     def isEvaluated( self ):
>         return self.__evaluate
>
>     def getXnameUnits( self ):
>         '''
>         units:String of independent variable
>         '''
>         return self.getUnitName()
>
>     def getXname( self ):
>         '''
>         name:String of independent variable
>         '''
>         return self.__xname
>
>     def getData( self ):
>         '''
>         dependence data as list of tuples that are ordered pairs (x,y)
>         '''
>         if self.__dataSet is not None:
>             return self.__dataSet
>         else:
>             raise DependenceException, "Error: Dependence Dataset not
> defined"
>
>     def getFunction( self ):
>         '''
>         f(x) dependence function of single independent variable x: y=f
> (x)
>         '''
>         if self.__dependentFunction is not None:
>             return self.__dependentFunction
>         else:
>             raise DependenceException, "Error: Dependence function not
> defined"
>
>     def setData( self, data ):
>         '''
>         set dependence data as list of tuples that are ordered pairs
> (x,y)
>         @param data: list of ordered pairs of (independent,dependent)
>         @type data: list of tuples (x,y)
>         '''
>         self.__dataSet=data
>         self.__interpolate=True
>
> #===================================================================
>         # create InterpolatingFunction object from Scientific Python
> package
>
> #===================================================================
>         for x, y in self.__dataSet:
>             self.x.append( x )
>             self.y.append( y )
>
>         self.x=np.asarray( self.x )
>         self.y=np.asarray( self.y )
>         self.vi=Ip( ( self.x, ), self.y )
>
>     def setFunction( self, function ):
>         '''
>         Set dependent function
>         @param function: y = f(x)
>         @type function: f(x)
>         '''
>         self.__dependentFunction=function
>         self.__evaluate=True
>
>     def interpolate( self, x ):
>         if self.__interpolate:
>             return self.vi( x )
>         else:
>             raise DependenceException, "Error: dependence data not
> defined"
>
>     def evaluate( self, x ):
>         '''
>         Evaluate using supplied univariate function (see setFunction)
>         @param x: independent variable
>         @type x: float
>         '''
>         if self.__dependentFunction is None:
>             raise DependenceException, "Error: Dependent function has
> not been specified"
>         else:
>             return self.__dependentFunction( x )
>
>
>
> class DataSet( object ):
>     '''
>     classdocs
>     '''
>     def __init__( self, x, y):
>         self.x=x
>         self.y=y
>
>
>     def getX(self):
>         return self.__x
>
>
>     def getY(self):
>         return self.__y
>
>
>     def setX(self, value):
>         self.__x = value
>
>
>     def setY(self, value):
>         self.__y = value
>
>
>     def delX(self):
>         del self.__x
>
>
>     def delY(self):
>         del self.__y
>
>     x = property(getX, setX, delX, "X's Docstring")
>
>     y = property(getY, setY, delY, "Y's Docstring")
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to