понедельник, 12 июля 2010 г.

NEW! Method declarations in Macro TSQL

Here is last submit info (Вот что было в последних обновлениях):


1) NEW method declaration support for interfaces
2) FIX _drop now can drop triggers
3) FIX procedure renaming applyed correctly (only in outer declaration)
4) FIX pseudo object '_' now dropped when core module loaded
5) NEW syntax shugar - allow call to dynamic sql in short style :

exec _ '<<< select * from {{@table}} where {{@field}} = ''{{@value}}'' >>>'
6) UPG addition comdivpreprocessor.x300_table_interface_parameters_embeder - adds parameters to interface definitions if not provided manually (@table and @useconstraints parameters)
7) NEW safe and simple procedures to ensure (create if not exists) of filegroups and files of database
8) NEW comdiv.mtsql.core.interfaces.sql - module - some our best practices of table schemas (especially for hibernate mapping), expressed as comdiv table interfaces


What is most interesting? (Что наиболее интересно?)
method declarations (Определения методов в интерфейсах)
Look at this code:
-- INTERFACE CREATING:
/*@
<name>comdiv_table_interface.code</name>
<field name='code' type='nvarchar(255)' constraint='not null unique default cast(newid() as nvarchar(255))' />
<method name="id">
        create function __ (@code nvarchar(255)) returns bigint as begin
            return (select top 1 id from THIS where code = @code )
        end
</method>
<method name="code">
        create function __ (@id bigint) returns nvarchar(255) as begin
            return (select top 1 code from THIS where id = @id )
        end
</method>
@*/
create proc _ as begin return end




-- INTERFACE USAGE
GO
if(object_id('__X') is not null drop table __X
GO
_table '__X'
GO
_interface '__X', 'code'
GO
insert __X (code) values ('a')
GO
select dbo.__X_id('a')           -- 10
select dbo.__X_code(10)      -- 'a'
GO


Significant changes:
1) methods a totally defined on declarative maner
2) automatical name generation - don't need to copy in method implementation (use pseudo name __ instead)
3) special 'keyword' THIS that means table to which interface is applyed

(RU)
Значимые изменения:
1) методы полностью формируются в декларативной части
2) автоматическая генерация имен - не надо дублировать в реализации метода, используется псевдо-имя __
3) специальное "ключевое слово" THIS - обозначает целевую таблицу, к которой применяется интерфейс

Комментариев нет: