Search

Languages

Other languages on request.

About Me

I am the "Lotus Technology & Productivity Advisor" for IBM Asia Pacific. I'm based in Singapore.

Ads by Google

Visitors

« How I got started with Lotus Notes | Main| Notes and Domino's most wanted »

Creating SQL Statements from form definitions

QuickImage I had an iteresting discussion with a customer this week. They use Domino and dotNet for their web applications. Their decission criteria when to use what: if the data of the application needs to be fed into their data warehouse at a later point of time, they use dotNet since storage there typically ends up in an RDBMS. The biggest problem they face, in their own voice: "Our users are pretty spoiled from Domino. They expect days as turnaround time for applications. Using dotNet it takes at least three times longer."
So I asked why they don't use DECS to connect to the RDBMS. They could develop the application in Notes/Domino and once the app does what the user wants just add the tables in the RDBMS and link them up using DECS. They asked back if there is a way to generate the table or at least the create table statement from Domino directly. The short answer: Yes, you can, however you need to make decissions on datatypes and field length. The long answer: you need Domino Designer (for the Tools - DXL Utilities - Transformer ... menu) and a little XSLT stylesheet.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output xmlns:xml="http://www.w3.org/XML/1998/namespace" method="text" version="1.0" encoding="UTF-8" xml:space="preserve" omit-xml-declaration="yes"></xsl:output>
<xsl:template match="/">
<!-- We only look at forms for the time being, when I have enough time I add basic support for subforms, at least the fixed ones -->
<xsl:apply-templates select="//d:form"></xsl:apply-templates>
</xsl:template>
<xsl:template match="d:form">
<xsl:param name="formName">
<xsl:choose>
<xsl:when test="@alias">
<xsl:value-of select="@alias"></xsl:value-of>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
CREATE TABLE
<xsl:value-of select="$formName"></xsl:value-of>
( DocID CHAR(32) NOT NULL,
<xsl:apply-templates select="//d:field[@kind!='computedfordisplay']"></xsl:apply-templates>
PRIMARY KEY (DocID));
</xsl:template>
<!-- Here we do map the various field types. You want to revisit the form -->
<xsl:template match="d:field">
<xsl:value-of select="@name"></xsl:value-of>
<xsl:choose>
<xsl:when test="@type='text'">
VARCHAR(254),
</xsl:when>
<xsl:when test="@type='keyword'">
VARCHAR(254),
</xsl:when>
<xsl:when test="@type='datetime'">
DATE,
</xsl:when>
<xsl:when test="@type='number'">
LONG,
</xsl:when>
<xsl:when test="@type='names'">
VARCHAR(254),
</xsl:when>
<xsl:when test="@type='richtext'">
BLOB,
</xsl:when>
<!-- If we forgotten a data type -->
<xsl:otherwise>
VARCHAR(254),
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Sample of a specia case consideration for number fields -->
<xsl:template match="d:field[@type='number']">
<xsl:value-of select="@name"></xsl:value-of>
<xsl:choose>
<xsl:when test="d:numberformat/@format='fixed'">
DECIMAL(31,
<xsl:value-of select="d:numberformat/@digits"></xsl:value-of>
),
</xsl:when>
<xsl:otherwise>
LONG,
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Comments

Gravatar Image1 - @Axel: yes xPages looks promising. However we needed a solution for the customers current 6.5 environment.
Emoticon stw

Gravatar Image2 - want to know full detail description about ADO.Net Click
<a href="{ Link } Source Code</a>

Gravatar Image3 - Very interesting observation from your customers regarding the comparison of turnaround times.

Gravatar Image4 - Truely interesting.
But you will have to manually postprocess the generated SQL-DDL.

Whats missing for the real world are for example:
- exclude domino fields from persistence.
- field specific constraints (e.g. NOT NULL, NUMERIC(8,2), etc. Also currently its easier to validate those constraints on the form by using .NET.
- Using character as the primary key is slow (bigint or integer are much faster)
- foreign keys aka referential integrety. Again using domino-UniqueID tends to be slow when being used in sql-join statements.

I think xPages has a potential to solve a lot of those issues, in case they come up.
And lots of RDBMS solutions use to be transactional by nature of business requirements. Domino isn't designed for that.
Chances are that we could get that on Expeditor with plugging-in openSource java frameworks which support it very well (especially together with xPages).

Gravatar Image5 - Stephan, I just wanted to point out that it depends on the requirements for the rdbms database. Depending on usage scenarios, they can result in demand for a much stricter ddl-sql script.
Dxl is great and it has opened a lot of new opportunities. I use it a lot for the most astoundingly divers tasks as admin-automation or as input to translation services.

Gravatar Image6 - Hi, Stephan, why not use LEI (Lotus Enterprise Integrator) ?

Gravatar Image7 - @Chen: Buying LEI just to create a table might be a little overkill. So customers bulk at it. And as long record creation happens on the Domino side only DECS is sufficient. For more advanced use LEI is a good choice. I actually like it a lot.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)

Disclaimer

This site is in no way affiliated, endorsed, sanctioned, supported, nor enlightened by Lotus Software nor IBM Corporation. I may be an employee, but the opinions, theories, facts, etc. presented here are my own and are in now way given in any official capacity. In short, these are my words and this is my site, not IBM's - and don't even begin to think otherwise. (Disclaimer shamelessly plugged from Rocky Oliver)

© 2003 - 2009 Stephan H. Wissel - all rights reserved as listed here: Creative Commons License
Unless otherwise labeled by its originating author, the content found on this site is made available under the terms of an Attribution/NonCommercial/ShareAlike Creative Commons License, with the exception that no rights are granted -- since they are not mine to grant -- in any logo, graphic design, trademarks or trade names of any type.

Get Firefox Use OpenDNS