对于为 DBIx::Class (::Schema::Loader) 转储 Sybase 模式的 Perl 库,我需要能够自省 DEFAULT 和计算列。
假设我们有:
create table bar (
id INTEGER IDENTITY PRIMARY KEY,
foo VARCHAR(10) DEFAULT 'foo',
adt AS getdate(),
ts timestamp
)
据我所知,这是:
select substring(c.name,1,5) name, c.cdefault, c.computedcol from syscolumns c
join sysobjects o on c.id = o.id where o.name = 'bar' and o.type = 'U'
name cdefault computedcol
---------- ----------- -----------
id 0 NULL
foo 602182610 NULL
adt 0 618182667
ts 0 NULL
这告诉我,列 'foo' 有一个 id 为 602182610 的存储过程,它返回值。如何从此 id 获取原始的 DEFAULT 'foo'?
时间戳列没有计算列对象,也没有默认存储过程,但我不知何故需要知道它实际上是一个时间戳列。查看 DBI 返回的数据类型告诉我它是“varbinary”,即时间戳的内部表示。我怎么知道它是不是一个?
它还告诉我列“adt”是一个计算列,该列的对象具有 id 618182667。
在 sysobjects 中查找该 ID 并没有告诉我什么似乎有用的信息,除了:
select substring(name,1,15) name, type from sysobjects where id = 618182667
name type
------------------------------ ----
bar_adt_6181826 C
非常感谢任何帮助。