I must be doing something wrong here

On Nov 3, 2:14 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Nov 3, 2008, at 5:10 PM, john.goodleaf wrote:
>
>
>
>
>
> > I'd like to map to a selectable, but that selectable should contain
> > the result of a scalar function. I'm unsure how best to accomplish it.
> > In raw SQL, I'd write something like:
> > select P.SubjectId,
> >          P.SubjectName,
> >          V.VariableName,
> >          D.RecordID,
> >          D.Data,
> >          dbo.fnLocalizedInstanceName('eng', I.InstanceID) as
> > InstanceName <--- Here's the function
> >         <from a bunch of joined tables>
>
> > I want this ORM'd, but I'm not sure where or how to invoke the
> > localization function. Is it better done in the Table definition? How?
> > Is this something I can put in the mapper() function? Basically,
> > instead of the reflected column, I want to retrieve the result of a
> > function?
>
> > This is probably easy, but I haven't found it in the docs yet.
> > Thanks,
>
> use column_property() in conjunction with  
> func.dbo.fnLocalizedInstanceName('eng', column).   Some docs are in  
> the "mapper" chapter of the docs.


I must be doing something wrong here. I've put a function call into
the mapper like so:

    mapper(Instance, instances,
           properties={'LocalInstanceName':
            column_property(select(
                [func.fnLocalizedInstanceName(bindparam('eng'),
 
bindparam(instances.c.InstanceID)) ]))} )

When I attempt to run a select against a particular instance (known to
exist) I get the following error:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', '[42000]
[FreeTDS][SQL Server]Statement(s) could not be prepared. (8180)
(SQLPrepare)') 'SELECT (SELECT fnLocalizedInstanceName(?, ?) AS
[fnLocalizedInstanceName_1]) AS anon_1, [Instances].[InstanceID] AS
[Instances_InstanceID], [Instances].[FolderID] AS
[Instances_FolderID], [Instances].[InstanceName] AS
[Instances_InstanceName], [Instances].[Access] AS [Instances_Access],
[Instances].[StartWin] AS [Instances_StartWin], [Instances].[Target]
AS [Instances_Target], [Instances].[EndWin] AS [Instances_EndWin],
[Instances].[Overdue] AS [Instances_Overdue], [Instances].[Close] AS
[Instances_Close], [Instances].[InstanceActive] AS
[Instances_InstanceActive], [Instances].[ParentInstanceID] AS
[Instances_ParentInstanceID], [Instances].[Created] AS
[Instances_Created], [Instances].[Updated] AS [Instances_Updated],
[Instances].[SubjectID] AS [Instances_SubjectID], [Instances].[Guid]
AS [Instances_Guid], [Instances].[SubjectMatrixID] A
S [Instances_SubjectMatrixID], [Instances].[ServerSyncDate] AS
[Instances_ServerSyncDate], [Instances].[InstanceDate] AS
[Instances_InstanceDate], [Instances].[Deleted] AS
[Instances_Deleted], [Instances].[RequiresSignature] AS
[Instances_RequiresSignature], [Instances].[InstanceRepeatNumber] AS
[Instances_InstanceRepeatNumber], [Instances].[IsUserDeactivated] AS
[Instances_IsUserDeactivated] \nFROM [Instances] \nWHERE [Instances].
[InstanceID] = ?' [None, None, 108893]
>>>

You can see the parameters are None None and 108893 (the id known to
exist). I want them to be 'eng' <InstanceID> and 108893. Please tell
me I've overlooked something simple.
Environment:
SQL Server 2005 (don't blame me)
pyodbc + FreeTDS + unixODBC on linux.

Thanks,
John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to