Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need new FbDataReader methods [DNET546] #522

Closed
firebird-automations opened this issue Feb 18, 2014 · 2 comments
Closed

Need new FbDataReader methods [DNET546] #522

firebird-automations opened this issue Feb 18, 2014 · 2 comments

Comments

@firebird-automations
Copy link

Submitted by: Gabor Lakatos (luckye)

I have new extension form FbDataReader class. I extend Get... (GetString, GetInt32, etc) methods for new parameters. Example: GetString("FIELDNAME", "DefaultValue").

The code:

using System;
using FirebirdSql.Data.FirebirdClient;

public static class FbDataReaderEx
{
public static bool GetBoolean(this FbDataReader oR, string FieldName, bool Default)
{
if (oR.IsDBNull(oR.GetOrdinal(FieldName)))
{
return Default;
}
else
{
return oR.GetBoolean(oR.GetOrdinal(FieldName));
}
}

public static byte GetByte\(this FbDataReader oR, string FieldName, byte Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetByte\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static DateTime GetDateTime\(this FbDataReader oR, string FieldName, DateTime Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetDateTime\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static decimal GetDecimal\(this FbDataReader oR, string FieldName, decimal Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetDecimal\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static double GetDouble\(this FbDataReader oR, string FieldName, double Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetDouble\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static Type GetFieldType\(this FbDataReader oR, string FieldName\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return null;
    \}
    else
    \{
        return oR\.GetFieldType\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static float GetFloat\(this FbDataReader oR, string FieldName, float Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetFloat\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static Guid GetGuid\(this FbDataReader oR, string FieldName, Guid Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetGuid\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static Int16 GetInt16\(this FbDataReader oR, string FieldName, Int16 Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetInt16\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static Int32 GetInt32\(this FbDataReader oR, string FieldName, Int32 Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetInt32\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static Int64 GetInt64\(this FbDataReader oR, string FieldName, Int64 Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetInt64\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static string GetString\(this FbDataReader oR, string FieldName, string Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetString\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static object GetValue\(this FbDataReader oR, string FieldName, object Default\)
\{
    if \(oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\)\)
    \{
        return Default;
    \}
    else
    \{
        return oR\.GetValue\(oR\.GetOrdinal\(FieldName\)\);
    \}
\}

public static bool IsDBNull\(this FbDataReader oR, string FieldName\)
\{
    return oR\.IsDBNull\(oR\.GetOrdinal\(FieldName\)\);
\}

}

I would be happy if the new procedures would appear in the new version.

Thanks,
Gabor

@firebird-automations
Copy link
Author

Commented by: @cincuranet

This is not part of http://ADO.NET as it's easily solvable with extension methods (you can even provide publicly).

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants