//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// DataHelpers.SQL satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using u = user_rtx;

namespace DataHelpers.SQL {

partial class HResultSetReader {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static T? VAL_N<T>( string fieldName ) where T: struct =>
   HDbQuery.GetFieldValue<T?>( fieldName );

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static string? STR_N( string fieldName ) =>
   GET<string?>( fieldName, true );
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static string? NS_N( string fieldName )
{
   string? str = GET<string?>( fieldName, true );
   return str!=null ? HDbQuery.NormalizeStrValue( str ) : null;
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static int? INT_N( string fieldName ) =>
   VAL_N<int>( fieldName );
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static long? BIGINT_N( string fieldName ) =>
   VAL_N<long>( fieldName );

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static double? FP_N( string fieldName ) =>
   VAL_N<double>( fieldName );

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static decimal? DEC_N( string fieldName ) =>
   VAL_N<decimal>( fieldName );

//--------------------------------------------------------------------------------------------------

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static bool? BOOL_N( string fieldName ) =>
   VAL_N<bool>( fieldName );

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static DateTime? DT_N( string fieldName ) =>
   VAL_N<DateTime>( fieldName );
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static DateTime? UTC_N( string fieldName )
{
   var dt = VAL_N<DateTime>( fieldName );
   return dt.HasValue ? (DateTime?)dt.Value.ToUniversalTime() : null;
}

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static Guid? GUID_N( string fieldName ) =>
   VAL_N<Guid>( fieldName );

//--------------------------------------------------------------------------------------------------

/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static byte[]? BINARY_N( string fieldName ) =>
   GET<byte[]?>( fieldName, true );

//--------------------------------------------------------------------------------------------------
/*
/// <exception cref="InvalidOperationException" />
/// <exception cref="InvalidCastException" />
/// <exception cref="HDatabaseException" />
[u.async_local]
public static ...? ..._N( string fieldName ) =>
   VAL_N<...>( fieldName );
   GET<...?>( fieldName );
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HResultSetReader

} // DataHelpers.SQL
