1

I am using Elixir to connect to MSSQL database. The database has a table with a computed column in it. However, when I update other columns in the object and commit the changes, python tells me I can't insert to the computed column.

I am using autoload so in my model:

class Slot(Entity):
    using_options(tablename='tbScheduleSlots', autoload=True)
    using_table_options(schema='sch')

I create a Slot and give it some values then commit:

ss = Slot(StartDateTime='2012-01-01 13:00:00:000', Program_ID=1234, etc)
session.commit()

Important note!! I do not give the ss object any value for EndDateTime because that is a computed field. So effectively, I'm not passing anything back to the database for that field.

Error:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', '[42000] [FreeTDS][SQL Server]The column "EndDateTime" cannot be modified because it is either a computed column or is the result of a UNION operator. (271) (SQLPrepare)') 'INSERT INTO sch.[tbScheduleSlots] ([Program_ID], [SlotType_ID], [StartDateTime], [EndDateTime], [Duration], [Description], [Notes], [State], [MasterSlot_ID]) OUTPUT inserted.[ID_ScheduleSlot] VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' (5130, 1, '2012-01-01 13:00:00:000', None, None, None, None, 2, None)

Ben
  • 51,770
  • 36
  • 127
  • 149
MFB
  • 19,017
  • 27
  • 72
  • 118
  • Much more information needed! How do you define your table class? How are you updating columns? What error message are you seeing? Some code snippets at least are needed. – seb Mar 29 '11 at 15:05
  • you're right, sorry. Hopefully my edits are better – MFB Mar 29 '11 at 16:14
  • I wonder if there's an option to tell it to ignore computed fields or certain fields by name? – HardCode Apr 01 '11 at 14:49

1 Answers1

0

Ehhh, I'm not a Python programmer, but it appears that this line:

using_options(tablename='tbScheduleSlots', autoload=True)

which is using autoload is probably what is adding [EndDateTime] to the INSERT statement (as shown in your error message). Looks like that is the line that tells Python the metadata of the underlying table (i.e. the fields in the table). Look for a way to define the columns to be updated manually. Relying on Python to build the INSERT appears to be automatically including [EndDateTime] in the underlying query.

HardCode
  • 6,497
  • 4
  • 31
  • 54
  • You're right that I'm probably expecting too much to have this table autoload. I'll try defining this table manually. Thanks! – MFB Mar 31 '11 at 08:28