Package generalDatabase
Class SQLTypes
java.lang.Object
generalDatabase.SQLTypes
- Direct Known Subclasses:
MSAccessSQLTypes
,MySQLSQLTypes
,PostgreSQLTypes
,SqliteSQLTypes
,UCanAccessSqlTypes
Utilities for converting between java.sql.types numeric
and text formats.
SQL format can be slightly different between different databases. For example, MS Access allows you to put column names in "" which then enables you to use otherwise reserved words. MySQL on the other hand, will not let you do this.
This base class contains some default behaviours, but expect them to be overridden in many instances.
- Author:
- Doug Gillespie
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateTableItem
(ResultSet columnData, ResultSetMetaData cmd) Work out some column information from the column result set.formatColumnName
(PamTableItem tableItem) Format a column name from a table item.formatColumnName
(String columnName) Format the column name.formatDateTimeMatchString
(long timeMilliseconds) Allow slightly different formatting when we're trying to get an exact match of a milliseconds time.formatDBDateTimeQueryString
(long timeMilliseconds) Format the time for insertion into a WHERE %s BETWEEN %s clause, mostly used by the Viewer.formatTableName
(String tableName) Any bespoke formatting of table namesgetLocalTimeStamp
(long millis) Get a local timestamp using system default time zone.getLongValue
(Object object) Try to read a long value - which might be an Integer or some other type depending on the database.getTimeStamp
(Long timeMillis) Get a time object in the appropriate format for whichever database we're using.boolean
makeDouble
(Float value) Make a Double object from a FloatmakeDouble
(Object value) Try to make a Double value out of any type of object.Make a Float object from a DoubleTry to make a Float object out of any type of object.makeInList
(Object[] array) Make an 'IN'list, without it's column name,e.g.static Long
millisFromTimeStamp
(Object timeValue) convert a time stamp read from a database into milliseconds, bu tonly rounded to the nearest secondvoid
setAllowBlanks
(boolean allowBlanks) int
stringToLength
(String typeName) int
stringToType
(String typeName) int
systemSqlType
(int sqlType) Some SQL types are unavailable on some systems, so qutomatically swap them for something else.typeToString
(int sqlType, int length) Converts a numeric SQL type and length to a text string that can be used in SQL statements.typeToString
(int sqlType, int length, boolean counter) typeToString
(PamTableItem tableItem)
-
Constructor Details
-
SQLTypes
public SQLTypes()
-
-
Method Details
-
typeToString
-
typeToString
Converts a numeric SQL type and length to a text string that can be used in SQL statements. The length parameter is generally only required by text and character types.- Parameters:
sqlType
- SQL type as defined in java.sql.Typeslength
- length of character and text fields- Returns:
- string representation of the type
-
typeToString
-
createTableItem
Work out some column information from the column result set.- Parameters:
columnData
-cmd
-- Returns:
-
stringToLength
-
stringToType
-
formatColumnName
Format a column name from a table item. N.B that this functin can use the 'allowblanks' variable to make column names with blanks - allow blanks can be used for reading and converting old databases, but not recommended for anything being output from PAMGuard.- Parameters:
tableItem
-- Returns:
- a formatted column name.
-
formatColumnName
Format the column name. Formats may be slightly different for different DBMS's. e.g. MS Access can put quotes around names. OODB requires them to be all upper case, etc.- Parameters:
columnName
-- Returns:
- formatted column name.
-
formatTableName
Any bespoke formatting of table names- Parameters:
tableName
- input table name- Returns:
- modified table name (e.g. to lower case)
-
systemSqlType
public int systemSqlType(int sqlType) Some SQL types are unavailable on some systems, so qutomatically swap them for something else.- Parameters:
sqlType
-- Returns:
-
getTimeStamp
Get a time object in the appropriate format for whichever database we're using.- Parameters:
timeMillis
- Time in milliseconds.- Returns:
- Appropriate object (Generally TimeStamp, but SWLite uses Long)
-
getLocalTimeStamp
Get a local timestamp using system default time zone.- Parameters:
millis
- time in milliseconds.- Returns:
- local timestamp.
-
millisFromTimeStamp
convert a time stamp read from a database into milliseconds, bu tonly rounded to the nearest second- Parameters:
timestamp
- GMT timestamp- Returns:
- time in milliseconds.
-
formatDBDateTimeQueryString
Format the time for insertion into a WHERE %s BETWEEN %s clause, mostly used by the Viewer. This has been wrapped here so that we can support a different format for SQLLite- Parameters:
timeMilliseconds
- Time in milliseconds- Returns:
- String to insert into a where clause.
-
formatDateTimeMatchString
Allow slightly different formatting when we're trying to get an exact match of a milliseconds time.- Parameters:
timeMilliseconds
- time in milliseconds.- Returns:
- formatted time string.
-
getLongValue
Try to read a long value - which might be an Integer or some other type depending on the database.- Parameters:
object
- Hopefully Long, but my be something else- Returns:
- Long or null.
-
makeFloat
Make a Float object from a Double- Parameters:
value
- Double value- Returns:
- Float value
-
makeFloat
Try to make a Float object out of any type of object.- Parameters:
value
- value- Returns:
- Float object or null.
-
makeDouble
Make a Double object from a Float- Parameters:
value
- Float value- Returns:
- Double value
-
makeDouble
Try to make a Double value out of any type of object.- Parameters:
value
- value- Returns:
- Float object or null.
-
isAllowBlanks
public boolean isAllowBlanks()- Returns:
- the allowBlanks
-
setAllowBlanks
public void setAllowBlanks(boolean allowBlanks) - Parameters:
allowBlanks
- the allowBlanks to set
-
makeInList
Make an 'IN'list, without it's column name,e.g. IN ('SPW','DO','HP')- Parameters:
array
- of objects to include in the list.- Returns:
- combined list.
-