KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Comments Within SQL Statements in 4D v12
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: November 1, 2010

In 4D v12 has two different ways to comment SQL code.

  1. Line comments

    Line comments start with two dashes(–) and ends with carriage returns. Everything the between two dashes(–) and carriage return is considered a comment. These comments can be placed anywhere in the code. These comments can be placed after code in the same line and everything before two dashes (–) will execute like normal. Code after two dashes(–) will not be executed and considered as a comment.

    Example:
    SELECT *
        –---This table name
    FROM <<[Sales]Products>>
    WHERE ProductID > 10 –---This is filter condition

  2. Block comments

    Block comment starts with a forward-slash and asterisk (/*) and end with an asterisk and forward-slash (*/). Everything between the forward-slash and asterisk (/*), before the next asterisk and forward-slash (*/), is considered as comments. These comments are usually placed before or after big chunk of code, however they can be placed anywhere in the code. These comments can span more than one line.

    Example:
    /*This is an example of block comment
    Following code is an example of the same retrieve
    and filter condition*/
    SELECT *
    FROM <<[Sales]Products>>
    WHERE ProductID > 10

The images below show how comments work in 4D v12 and are enhanced in the 4D Method Editor.

In this first image notice that there is a code folding indicator beside the beginning of the block comment (/*):



In the 4D v12 method editor the block comment shown in the image above can be folded as shown here:


During development, it is often necessary to have blocks of code for debug purposes. If the debug code is lengthy, commenting and uncommenting it can be tedious. But if you put either a '--' in front of each line or a '/*' at the front and a '*/' at the end of each line, you can comment and uncomment the code block with a couple of keystrokes. Here are examples of each method:

Commented code


Uncommented code


Just by adding or deleting two dashes at the beginning of the code block, the entire block can be commented or uncommented