com.googlecode.jdbw
Interface SQLDialect

All Known Implementing Classes:
DefaultSQLDialect, H2SQLDialect, SybaseASESQLDialect

public interface SQLDialect

This class contains methods to assist you in formatting SQL queries adjusted to the target database type

Author:
Martin Berglund

Method Summary
 String escapeIdentifier(String identifier)
          Takes the name of a database object (table, column, etc) and returns the name wrapped in characters that marks it's an identifier.
 String escapeString(String string)
          Returns a string with all special characters replaced with their proper escape sequences.
 String formatDate(Date date)
          Formats a java Date into the preferred date string format for this database server type, probably YYYY-MM-DD
 String formatDateTime(Date timestamp)
          Formats a java Date into the preferred date time string format for this database server type, probably YYYY-MM-DD HH:MM:SS.ZZZ
 String formatTime(Date date)
          Formats a java Date into the preferred time string format for this database server type, probably HH:MM:SS.ZZZ
 String formatValue(Object value, int targetType)
          Formats a generic object into a String that can be inserted into a dynamically constructed SQL statement.
 String[] getCreateTableStatement(String schemaName, String name, List<Column> columns, List<Index> indexes)
           
 String getDropTableStatement(String catalog, String schema, String tableName)
           
 String getSingleLineCommentPrefix()
           
 boolean isCompatible(int fromSqlType, int toSqlType)
           
 Object safeType(Column targetColumn, Object object)
          Attempts to convert a particular value to an acceptable format.
 

Method Detail

escapeIdentifier

String escapeIdentifier(String identifier)
Takes the name of a database object (table, column, etc) and returns the name wrapped in characters that marks it's an identifier. Use this if, for example, your column names may be colliding with keywords on the server.

Parameters:
identifier - string to wrapp
Returns:
The input string wrapped as an identifier

escapeString

String escapeString(String string)
Returns a string with all special characters replaced with their proper escape sequences. You don't need to do this for strings passed in as parameters, since the JDBC driver will do it for you.

Parameters:
string - String to convert
Returns:
The original string with special characters escaped

formatDate

String formatDate(Date date)
Formats a java Date into the preferred date string format for this database server type, probably YYYY-MM-DD

Parameters:
date - Date to format
Returns:
Date formatted as a string

formatDateTime

String formatDateTime(Date timestamp)
Formats a java Date into the preferred date time string format for this database server type, probably YYYY-MM-DD HH:MM:SS.ZZZ

Parameters:
date - Date to format
Returns:
Date formatted as a string

formatTime

String formatTime(Date date)
Formats a java Date into the preferred time string format for this database server type, probably HH:MM:SS.ZZZ

Parameters:
date - Date to format
Returns:
Date formatted as a string

formatValue

String formatValue(Object value,
                   int targetType)
Formats a generic object into a String that can be inserted into a dynamically constructed SQL statement. You'll need to supply the type you want the value to be in the database context through the targetType parameter. Note: Throws IllegalArgumentException is the objects cannot be formatted

Parameters:
value - Value to be formatted
targetType - java.sql.Types constant of the type you want to format the value as
Returns:
String with the value formatted as the specified type

getCreateTableStatement

String[] getCreateTableStatement(String schemaName,
                                 String name,
                                 List<Column> columns,
                                 List<Index> indexes)

getDropTableStatement

String getDropTableStatement(String catalog,
                             String schema,
                             String tableName)

getSingleLineCommentPrefix

String getSingleLineCommentPrefix()
Returns:
What to put in front of a line to comment it out

isCompatible

boolean isCompatible(int fromSqlType,
                     int toSqlType)
Returns:
True if this database can convert data of type fromSqlType to type toSqlType

safeType

Object safeType(Column targetColumn,
                Object object)
Attempts to convert a particular value to an acceptable format. Given a column on the server and the value we want to put into this column, the method will try to convert the value into a format that is compatible with the column.

Parameters:
targetColumn - Column we want to insert into
object - Object to insert
Returns:
A compatible value for the target column


Copyright © 2012. All Rights Reserved.