SQL call formatting style

Gervase Markham gerv at mozilla.org
Tue Mar 25 08:32:52 UTC 2003


Guys,

The new DBI stuff has raised a few issues about how we write SQL 
statements in Perl code (see bug 180635 for some discussion.) IMO, it's 
important to have a consistent style, because it makes code easier to 
read. What that style is is far less important than the consistency.

One of the factors is multi-line strings. Myk: am I correct in saying 
that you have asked for
"separate quotes for " .
"each line of the string"
because it makes logs look better than
"one string which runs
  over multiple lines"?

My suggestion is as follows:

   my ($comma, $separated, $list, $of, $vars, $on, $one, $line) =
     $dbh->some_longwinded_methodname("SELECT some SQL " .
				     "ON multiple lines " .
				     "IF necessary " .
				     "AND enclosed in quotes " .
				     "BECAUSE we all understand them " .
                                      "WITH placeholders ?, ?, ?",
                                      undef,
                                      $placeholder, $variables, $here);

but obviously it's only a suggestion. The last few lines can be 
block-shifted to the left if necessary to make more room.

In contrast, bbaetz recently went for:

     my ($id,
         $login,
         $name,
         $mybugslink) = $dbh->selectrow_array(qq{SELECT userid,
                                                        login_name,
                                                        realname,
                                                        mybugslink
                                                   FROM profiles
                                                  WHERE $cond},
                                              undef,
                                              $val);

Gerv




More information about the developers mailing list