←Select platform

FormatSql Method

Summary

Pretty-prints SQL text using various FormatSqlOptions.

Syntax

C#
C++/CLI
public static string FormatSql( 
   string sqlInputString, 
   FormatSqlOptions options 
) 
public:  
   static String^ FormatSql( 
      String^ sqlInputString, 
      FormatSqlOptions^ options 
   ) 

Parameters

sqlInputString

A string containing the SQL text to be formatted.

options

A FormatSqlOptions object that specifies various options that affect the result.

Return Value

A formatted SQL string.

Example

C#
using Leadtools.Dicom; 
using Leadtools.Dicom.Common; 
using Leadtools.Dicom.Common.Extensions; 
using Leadtools; 
using Leadtools.Dicom.Common.Linq.BasicDirectory; 
using Leadtools.Dicom.Common.DataTypes; 
 
using Leadtools.Codecs; 
 
 
public static void FormatSqlExample() 
{ 
   // unformatted SQL  
   string sql = 
      $"SELECT Patient.PatientID FROM Instance " + 
      $"INNER " + 
      $"JOIN Series on Instance.SeriesInstanceUID " + 
      $"= Series.SeriesInstanceUID INNER JOIN Study on  Series.StudyInstanceUID = " + 
      $"Study.StudyInstanceUID INNER JOIN Patient on Study.PatientID = Patient.PatientID WHERE " + 
      $"Patient.PatientID Like '%1%' ORDER BY PatientID"; 
 
   Formatters.FormatSqlOptions options = new Formatters.FormatSqlOptions(); 
   options.NewLineBeforeFromClause = true; 
   options.NewLineBeforeGroupByClause = true; 
   options.NewLineBeforeHavingClause = true; 
   options.NewLineBeforeJoinClause = true; 
   options.NewLineBeforeOrderByClause = true; 
   options.NewLineBeforeWhereClause = true; 
 
   string formattedSql = Formatters.FormatSql(sql, options); 
 
   // This is the result: 
   //  
   //    SELECT Patient.PatientID 
   //    FROM Instance 
   //    INNER JOIN Series on Instance.SeriesInstanceUID = Series.SeriesInstanceUID 
   //    INNER JOIN Study on Series.StudyInstanceUID = Study.StudyInstanceUID 
   //    INNER JOIN Patient on Study.PatientID = Patient.PatientID 
   //    WHERE Patient.PatientID Like '%1%' 
   //    ORDER BY PatientID 
 
   Console.WriteLine(formattedSql); 
} 

Requirements

Target Platforms

See Also

Formatters Class

Formatters Members

Leadtools.Dicom.Common.Extensions Namespace

Help Version 22.0.2023.1.30
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom.Common Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.