/**
 *
 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 **/
package lucee.runtime.query.caster;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.TimeZone;

public class OtherCast implements Cast {

	private final int type;

	public OtherCast(int type) {
		this.type = type;
	}

	@Override
	public Object toCFType(TimeZone tz, ResultSet rst, int columnIndex) throws SQLException {
		if (type != Types.SMALLINT) return rst.getObject(columnIndex);

		try {
			return rst.getObject(columnIndex);
		}
		// workaround for MSSQL Driver, in some situation getObject throws a cast exception using getString
		// avoids this
		catch (SQLException e) {
			try {
				return rst.getString(columnIndex);
			}
			catch (SQLException e2) {
				throw e;
			}
		}
	}

}
@@ -895,16 +895,68 @@
 imeZone;
+%0Aimport java.util.UUID;%0Aimport java.net.InetAddress;
 %0A%0Apublic
@@ -1203,22 +1203,35 @@
 ALLINT) 
-return
+%7B%0A%09%09%09Object value =
  rst.get
@@ -1255,17 +1255,403 @@
 x);%0A
-%0A%09%09try %7B%0A
+%09%09%09%0A%09%09%09// Drivers like Postgres like to return java.util.UUID instances instead of the string GUID %0A%09%09%09if( value instanceof UUID ) %7B%0A%09%09%09%09return ((UUID)value).toString();%0A%09%09%09%7D%0A%0A%09%09%09// Drivers like Postgres have a custom type that returns java.net.InetAddress %0A%09%09%09if( value instanceof InetAddress ) %7B%0A%09%09%09%09return ((InetAddress)value).toString();%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09return value;%0A%09%09%09%09%0A%09%09%7D else %7B%0A%0A%09%09%09try %7B%0A%09
 %09%09%09r
@@ -1686,18 +1686,20 @@
 dex);%0A%09%09
+%09
 %7D%0A
+%09
 %09%09// wor
@@ -1794,16 +1794,17 @@
 tring%0A%09%09
+%09
 // avoid
@@ -1810,16 +1810,17 @@
 ds this%0A
+%09
 %09%09catch 
@@ -1837,30 +1837,32 @@
 ion e) %7B%0A%09%09%09
+%09
 try %7B%0A
+%09
 %09%09%09%09return r
@@ -1891,18 +1891,20 @@
 ex);%0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%09catch
@@ -1920,24 +1920,25 @@
 ption e2) %7B%0A
+%09
 %09%09%09%09throw e;
@@ -1938,16 +1938,22 @@
 hrow e;%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D
@@ -1953,13 +1953,14 @@
 %09%09%7D%0A%09%09%7D%0A
+%0A
 %09%7D%0A%0A%7D

Support UUID and Inet DB types in OtherCast