javatools.database
Class SQLType

java.lang.Object
  extended by javatools.database.SQLType
Direct Known Subclasses:
MySQLDatabase.ANSIvarcharBin, PostgresDatabase.Postgretext, SQLType.ANSIBigint, SQLType.ANSIblob, SQLType.ANSIboolean, SQLType.ANSIchar, SQLType.ANSIfloat, SQLType.ANSIinteger, SQLType.ANSIsmallint, SQLType.ANSItext, SQLType.ANSItimestamp, SQLType.ANSIvarchar

public abstract class SQLType
extends java.lang.Object

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This abstract class provides a Wrapper for SQL datatypes. A datatype has a type code (from java.sql.Types) and a scale. For example, INTEGER(17) is a datatype. A datatype can convert a datum to a suitable string. E.g. a TIMESTAMP datatype will convert the datum "2006-09-18" to TIMESTAMP '2006-09-18 00:00:00.00'. Of course, the same SQL datatype is different for different database systems, so that different databases have to implement different classes for the same datatype.
Example:

     Database d=new OracleDatabase("user","password");     
     d.getSQLType(java.sql.Types.VARCHAR).format("Bobby's")
     -> 'Bobby"s'
     d=new MySQLDatabase("user","password","database");     
     d.getSQLType(java.sql.Types.VARCHAR).format("Bobby's")
     -> 'Bobby\'s'
See here for a comparison of database systems. This class provides the ANSI implementations with generous conversion capabilities.
Example:
    SQLType.ANSItimestamp.format("13th of May 1980")
    --> TIMESTAMP '1980-05-13 00:00:00.00'


Nested Class Summary
static class SQLType.ANSIBigint
           
static class SQLType.ANSIblob
           
static class SQLType.ANSIboolean
           
static class SQLType.ANSIchar
           
static class SQLType.ANSIfloat
           
static class SQLType.ANSIinteger
           
static class SQLType.ANSIsmallint
           
static class SQLType.ANSItext
           
static class SQLType.ANSItimestamp
           
static class SQLType.ANSIvarchar
           
 
Field Summary
static SQLType.ANSIBigint ansibigint
           
static SQLType.ANSIblob ansiblob
           
static SQLType.ANSIboolean ansiboolean
           
static SQLType.ANSIchar ansichar
           
static SQLType.ANSIfloat ansifloat
           
static SQLType.ANSIinteger ansiinteger
           
static SQLType.ANSIsmallint ansismallint
           
static SQLType.ANSItext ansitext
           
static SQLType.ANSItimestamp ansitimestamp
           
static SQLType.ANSIvarchar ansivarchar
           
 
Constructor Summary
SQLType()
           
 
Method Summary
abstract  java.lang.String format(java.lang.Object s)
          Formats an object to a valid SQL literal of the given type
 int getScale()
          Returns the scale java.sql.Types type
 int getTypeCode()
          Returns the java.sql.Types type
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ansivarchar

public static SQLType.ANSIvarchar ansivarchar

ansiblob

public static SQLType.ANSIblob ansiblob

ansitext

public static SQLType.ANSItext ansitext

ansichar

public static SQLType.ANSIchar ansichar

ansitimestamp

public static SQLType.ANSItimestamp ansitimestamp

ansiinteger

public static SQLType.ANSIinteger ansiinteger

ansismallint

public static SQLType.ANSIsmallint ansismallint

ansifloat

public static SQLType.ANSIfloat ansifloat

ansiboolean

public static SQLType.ANSIboolean ansiboolean

ansibigint

public static SQLType.ANSIBigint ansibigint
Constructor Detail

SQLType

public SQLType()
Method Detail

format

public abstract java.lang.String format(java.lang.Object s)
Formats an object to a valid SQL literal of the given type


getTypeCode

public int getTypeCode()
Returns the java.sql.Types type


getScale

public int getScale()
Returns the scale java.sql.Types type


main

public static void main(java.lang.String[] args)