in

ASP.NET Weblogs

Firoz Ansari's Weblog

  • Released - TinySQL v2.0 Code Generator

    I just released TinySQL code generator v2.0 with few bug fixes and a new feature of using separator tag for loop statement. You can now use {sap}{/sap} tags to place your separators inside loop.

    Here is the example of using {sap}{/sap} tags in TinySQL template:
    ** Generate Data Provider: Update/v2.0
    CREATE PROCEDURE [dbo].[usp_Update$table]{loop}
    @$field = $sp_type{sap},{/sap}{/loop}
    AS
    BEGIN
    UPDATE dbo.$table WITH (ROWLOCK)
    SET {loop}$field = @$field{sap},{/sap}
    {/loop}
    WHERE --TODO
    RETURN -1
    END

    And generated code from above template will be like:
    CREATE PROCEDURE [dbo].[usp_UpdateAction]
    @Id = NUMERIC,
    @Action = VARCHAR(250),
    @ProjectId = NUMERIC,
    @IsNextAction = BIT,
    @IsWaitingFor = BIT,
    @WaitingForNotes = VARCHAR(1000),
    @RemindOn = DATETIME,
    @IsDefer = BIT,
    @DeferDate = DATETIME,
    @IsDone = BIT,
    @Sequence = INT
    AS
    BEGIN
    UPDATE dbo.Action WITH (ROWLOCK)
    SET Id = @Id,
    Action = @Action,
    ProjectId = @ProjectId,
    IsNextAction = @IsNextAction,
    IsWaitingFor = @IsWaitingFor,
    WaitingForNotes = @WaitingForNotes,
    RemindOn = @RemindOn,
    IsDefer = @IsDefer,
    DeferDate = @DeferDate,
    IsDone = @IsDone,
    Sequence = @Sequence
    WHERE --TODO
    RETURN -1
    END

    Download: TinySQL v2.0

    You can also read my previous blog to learn more about TinySQL tool.
    TinySQL Code Generator

    Hope you will find this tool useful.

     

  • TinySQL Code Generator

    TinySQL is small and handy SQL script which can quickly generate consistent code snippet that you can paste in your project. It basically operates by reading schema of provided table and applying template to each column of table in order to generate code snippet.

    With TinySQL, you can create complete or specific portion of business class, business service, or data access layer. You can also generate repetitive code snippet like storing all DataReader columns into respective property of business object, or passing all object properties to SqlParameter in data access layer, or creating stored procedures for a table or creating simple update or insert statement in stored procedure etc.

    TinySQL is part of my daily development practice. I am using early version of TinySQL for 2 years now and found myself more productive with this tool. I usually keep SQL Management Studio open (like most Microsoft application developers) all the time with a dedicated query pane for TinySQL. Whenever I need to write any repetitive code based on schema of any table, I simply provide table name, tweak template per my requirement and execute the script. I then copy and paste generated code in my project. Yes, I do require making minor changes sometime in generated code to make it usable in my project but still TinySQL serves its purpose.

    TinySQL is definitely not a replacement of sophisticated code generation tools like CodeSmith, TierDeveloper, LLBLGen etc. Those tools are very advance and can generate code for whole project including user interface, business layer, data access layers and even store procedures. TinySQL can only generate basic code snippet that you can use in your existing code or project.

    Download Link: TinySQL

    Implementation of TinySQL is very simple and straight forward. It reads schema definition of all columns of provided table and template; it then render code by rotating loop for each column. Variable you have to take care in TinySQL are:

    @TableName: table name for which you want to generate code
    @PrintTableName: how above table name should display in generated code. You may have table “tblCategories” but you want “Category” for class name.
    @Template: Template for generated code

    Open TinySQL in SQL Management Studio, provide table name and template, press F5 to execute TinySQL and you will have generated code in result pane. Now you just have to copy generated code from result pane and paste in your project.

    To make customization of template more flexible, I have used few tags as placeholder for rendering respective entity. These tags are:

    $table : Table name
    $field : Column Name
    $type : .NET Data Type
    $default : .NET Default Value
    $sp_type : SQL Data Type
    $length : Column Max Length

    {loop} : Start Loop
    {/loop} : End Loop

    Suppose I want to generate snippet which has list of all columns of provided table. So value of TinySQL variables will be:

    SET @TableName = 'tblCategory'
    SET @PrintTableName = 'Category'
    SET @Template = '
    ** generate simple column list /v1.0
    $table: {loop}$field, {/loop}
    '

    It will generate code something like this:

    Category: Id, Language, ParentId, Name, SafeName, Right, Left, IsEnabled, DisplayOrder, Color,

    Note: first line of template is comment portion which can be used as template description, author, template version, additional comment etc.

    You can play with TinySQL to explorer more about this tool.

    Ok, so here are some practical examples of templates which explain the basic usage of TinySQL:

    1. Listing all fields of provided table.

    $table Fields:
    {loop}$field,
    {/loop}

    This template will generate list of field in separate lines.

    2. Creating Simple SELECT statement:

    SELECT {loop}$field, {/loop}
    FROM $table

    As I mentioned before, you may require minor modification sometime in generated code to use it in your project. Like in above case, you have to manual remove last comma from SELECT.

    3. Creating UPDATE statement

    UPDATE $table
    SET {loop}$field = @$field,
    {/loop}

    Again, you require removing last comma from generated code.

    4. Creating Update Stored Procedure:

    ** generate Data Provider: Update/v1.0
    CREATE PROCEDURE [dbo].[usp_Update$table]{loop}
    @$field = $sp_type,{/loop}
    AS
    BEGIN

    UPDATE dbo.$table WITH (ROWLOCK)
    SET {loop}
    $field = @$field,{/loop}
    WHERE --TODO

    RETURN -1
    END

    5. Creating simple insert statement:

    ** generate simple insert statement/v1.0
    INSERT INTO $table ({loop}[$field],{/loop}
    VALUES ({loop}@$field,{/loop}

    6. Now, let’s use TinySQL to generate code snippet in C# (or VB.NET) which assign entity values to respective parameters of stored procedure.

    ** generate Data Provider: Update Function/v1.0
    SqlDatabase database = new SqlDatabase(this._connectionString);
    DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.$table_Update", _useStoredProcedure);
    {loop}database.AddInParameter(commandWrapper, "@$field", DbType.$type, entity.$field );
    {/loop}

    7. And as last example, here is template to generate business entity in C#.

    ** generate basic business entity/v1.0<br>
    #region Using Directives</p>
    <p>using System;<br>
    using System.ComponentModel;<br>
    using System.Collections;<br>
    using System.Xml.Serialization;<br>
    using System.Runtime.Serialization;</p>

    <p>#endregion</p>

    <p>namespace MyNameSpace.Entities<br>
    {<br>
        ///<summary><br>
        /// An object representation of the “$table” table.<br>
        ///</summary><br>
        [Serializable, DataObject]<br>
        public class $table<br>
        {<br>
            #region Variable Declarations<br>
            {loop}<br>
            private $type _$field;{/loop}</p>

    <p>        #endregion Variable Declarations</p>

    <p>        #region Constructors</p>

    <p>        public $table()<br>
            {<br>
             {loop}_$field = $default;<br>
            {/loop}<br>
            }</p>

    <p>        #endregion</p>

    <p>        #region Properties<br>
            {loop}<br>
            public $type $field<br>
            {<br>
                get<br>
                {<br>
                    return this._$field;<br>
                }<br>
                set<br>
                {<br>
                    this._$field = value;<br>
                }<br>
            }<br>
            {/loop}<br>
            #endregion<br>
        }<br>
    }

    Like last example, you can even create complete business service or data access layer using TinySQL.

    I hope you will find this tool useful. Please post your comment and feedback here.

  • Launch Announcement: DOTENET (Digg Clone)

    Its give me immense pleasure to announcement .NET portal - DOTENET (URL: www.dotenet.com). It’s "Digg" style web application dedicated to .NET and relative technologies. This portal will serve as central hub to share articles, tutorials, blog post etc.

    When I was planning to create this portal two months back, I was sure that first release of this project will have minimum "must to have" features and later I will add features which are "good to have". And that’s why you will notice many blank pages on this portal. These blank pages are place-holder for features which I will add in coming weeks (depending upon available bandwidth).

    The desired goal of creating a community portal cannot be achieved without your active participation. Please register yourself to this portal and share any article or post which you think useful to .NET community. If you find any existing link useful in DOTNET portal, please vote for that link so that link can be push to popular segment.

    As you continue participating in this portal, please keep in mind that this community portal needs your feedback to remain alive. Please provide your feedback/opinion/suggestion to my blog (URL: Announcement: DOTENET)

    URL: Home Page

    URL: Registration Page

  • Vulnerable JavaScript Comments

    Today while checking balance in my banker’s web portal, which is self acclaimed as one of the most secured online banking portal of India, I curiously thought of inspecting their HTML content using View Source. But I really shocked (and I almost got heart attack) to see whole bunch of JavaScript comment placed all over their pages. Most interesting thing was that these JavaScript snippets not only tell you bug numbers, who have done those modifications, on which date, but also what was the actual issue and how they have resolved that issue. :)

    The most interesting part was:
    <script language="JavaScript1.2">
    function alert_keycode(){
    /*
    Abhilash.

    This script was added bcze on pressing enter key on pwd field used to get Submittted but since the Command Action invoked was diff one that of OK button, it was not producing desired results. The solution was create a temp hidden field and changing Pwd field name to that of Ok button dynamically, assigning tmp-hidden field name/value with original Pwd Field name/value.

    And submit is invoked

    */

    frm = document.confirmFrm;
    if(event.keyCode==13)
    {
    blah blah blah

    I love this “detailed” and technically well explained comment provided by developer in HTML code.

    On serious note, I never prefer to put these JavaScript comments in my code as you can realize from comments like these, it might give lead to reveal any vulnerability or security hole in application. Even if you don’t want to consider the increase of payload of page because of these JavaScript comment but still putting comments with all kind technical or business explanations is major security risk to your application. Don’t do that!

    IMO, these code comments are for developer and not for user. My suggestion to all web developers to use server side comments instead of any client side comment specially if you are developing application for financial institutions etc.

    What is your opinion if I modify above code like this:
    <script language="JavaScript1.2">
    function alert_keycode(){
    <%
    /*Abhilash.

    This script was added bcze on pressing enter key on pwd field used to get Submittted but since the Command Action invoked was diff one that of OK button, it was not producing desired results. The solution was create a temp hidden field and changing Pwd field name to that of Ok button dynamically, assigning tmp-hidden field name/value with original Pwd Field name/value.
    And submit is invoked
    */
    %>
    frm = document.confirmFrm;
    if(event.keyCode==13)
    {
    blah blah blah
    </script>

    I guess later one is more secured than the original one. Do you agree with me??

    Please provide your comment here:

    http://www.firoz.name/2006/05/26/vulnerable-javascript-comments/

  • Great collection of ASP.NET/C# Posters!

    Barone, Budge & Dominick has great collection of posters relating to ASP.NET, C#, Design Patterns, Software Process etc. Here is the link to these postors. Just check out this first:

    Great collection of ASP.NET/C# Posters!

  • Google Trends - .NET, ASP.NET, C#, VB.NET

    I was just exploring Google Trends and I have found a very interesting search pattern for .NET, ASP.NET, C#, VB.NET.

    Google Trends - .NET, ASP.NET, C#, VB.NET

     

  • Murphy’s Laws of .NET

    Here is the Murphy’s Laws of .NET. Its based on my previous experience with .NET. I am sure most of the .Net developers will identify themselves somewhere in these laws.

    Murphy’s Laws of .NET

    Actually, it should be Firoz’s Laws of .NET. :)

  • Color in Motion

    Do you know each color has its own personality and attitude? Like, blue color is known for its authority, calmness and confidence and can easily complemented with orange color. Or, red color which is known for it’s ambitious, alert and impatient. Or, yellow color which is known more for aspiration, forgiveness and happiness. Claudia Cortés has created a great movie “Color In Motion” starring some major colors. Very nice approach of depicting nature of each colors its communication and symbolism. And what a storyline of this movie!

     

     

  • Google Advanced Operators (Cheat Sheet)

    In continuation of my previous blog, here is another useful cheat sheet.

    Google Advanced Operators (Cheat Sheet)

     

    Take a print out and mount it at your workstation.

  • Web Development Cheat Sheets

    Dave Child has written some great cheat sheets which really a good reference for me as ASP.NET developer.

     

    Here is the list of some cheat sheets:

    JavaScript Cheat Sheet
    CSS Cheat Sheet
    HTML Character Entities Cheat Sheet
    MySQL Cheat Sheet

    It’s really helpful to me.

More Posts Next page »