DDL SQL Templates released!

Posts   
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Sep-2006 18:44:34   

We've released DDL SQL templates so you can generate DDL SQL from a project. Please see the announcements forum for details simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 22-Oct-2007 16:37:45   

Very helpful template.

But how must I modify the template, that it creates the DDL for the mapped entities and not for the whole schema (especially for the DDL_CE)?

Regards, Carlos

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Oct-2007 06:07:12   

Hi Carlos,

Only tables, PK's, FK's, UC's and sequences (if applicable) are generated. Views, stored procedures, indexes and triggers aren't.

You can access the file at \AdditionalTemplates\Templates\SqlServerSpecific\SQL\DDL_CE.lpt

You can find information about how to modify templates at Template Studio Documentation

David Elizondo | LLBLGen Support Team
Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 29-Oct-2007 11:50:41   

daelmo wrote:

Only tables, PK's, FK's, UC's and sequences (if applicable) are generated. Views, stored procedures, indexes and triggers aren't.

You can access the file at \AdditionalTemplates\Templates\SqlServerSpecific\SQL\DDL_CE.lpt

You can find information about how to modify templates at Template Studio Documentation

Yes I know. I have already changed some datatype issues in the template for my mobile database.

But what I want to know is, which collections do I have to iterate, so that the generated DDL contains only mapped entities and columns and not the whole catalog.

Regards, Carlo

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2007 06:52:01   

Hi Carlo,

As far as I know there isn't a collection that retrieves the _IDBTables _included in entities list. However I think you can do that manually:

<%
foreach(IDBTable table in schema.Tables.Values)
{   
        // new code... you can put this on a separate method...
    bool IsTableIncludedInProject = false;
    foreach(EntityDefinition includedEntity in _currentProject.Entities)
    {
        if (table.TableName == includedEntity.TargetName)
        {
            IsTableIncludedInProject = true;
        }
    }

        // emit "CREATE TABLE" only if the table is included in the project
    if (IsTableIncludedInProject)
    {
%>

CREATE TABLE [<%=schema.SchemaOwner%>].[<%=table.TableName%>] (
...

<%          
    } // new IF

...

No tested, but I think you got the idea wink This check must be on the further elements (DROP TABLES, ALTER TABLES, etc.) Let us know if you can make it.

David Elizondo | LLBLGen Support Team
Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 30-Oct-2007 10:51:53   

Hi daelmo,

it is much more simpler: (and there is no need to iterate for each table the _currentProject.Entities collection simple_smile )


<%
foreach(IDBTable table in schema.Tables.Values)
{   
        // emit "CREATE TABLE" only if the table is included in the project
    if (_currentProject.Entities[table.TableName] != null)
    {
%>

CREATE TABLE [<%=schema.SchemaOwner%>].[<%=table.TableName%>] (
...

<%          
    } // new IF

...


and it works smile

Thank you for the hint.

Kindly regards, Carlo

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2007 11:07:32   

You got it wink

The only problem with that code is that: if your entity's name is different to the mapped table (Table's name: Customers - Entity's name: Customer), the condition might return false. That's why I suggested entityDef.TargetName.

I assume you don't have such a problem, just be aware of that wink

Regards,

David Elizondo | LLBLGen Support Team
Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 30-Oct-2007 14:56:00   

Thanks, I take care about that issue.

The first part is nearly perfect. But how can I do the same thing with the mapped columns/fields of an entity. MappedTargetFields?

I canĀ“t find the right object/collection in the SDK documentation confused

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Oct-2007 10:42:09   

Please try the following:

_currentProject.Entities[table.TableName].Items[table.TableName].Fields

Please refer to the SDK reference manual. _currentProject.Entities[table.TableName] returns an EntityContainer EntityContainer.Items[entityName] returns an EntityDefinition, which has a Fields collection

Rushmore
User
Posts: 125
Joined: 27-Jan-2005
# Posted on: 02-Nov-2007 17:56:21   

Thanks, I give it a try.

Kindly regards, Carlo