SCM

[#1010994] Add composite type support

View Trackers | Feature Requests | Download .csv | Monitor

Date:
2011-02-20 12:28
Priority:
3
State:
Open
Submitted by:
Yaroslav Potapov (jaroslav)
Assigned to:
Nobody (None)
Category:
Group:
Resolution:
None
 
Summary:
Add composite type support

Detailed description
I propose to add composite type support like this (need to complete):
---------------------------------------------------------------------------
public class NpgsqlCProperty
{
public NpgsqlCProperty(string name, NpgsqlDbType type)
{
if (name == null) throw new ArgumentNullException("name");
if (type == null) throw new ArgumentNullException("type");
//TODO: other verifies
PName = name;
PType = type;

}
public string PName { get; private set; }
public NpgsqlDbType PType { get; private set; }
}


public class NpgsqlComposite
{
public NpgsqlComposite(string name, params NpgsqlCProperty[] properties)
{
if (name == null) throw new ArgumentNullException("name");
if (properties == null) throw new ArgumentNullException("properties");
Name = name;
_properties = new Dictionary<string, int>(properties.Length);
_values = new object[properties.Length];
_types = new NpgsqlDbType[properties.Length];
for (int i = 0 ; i < properties.Length ; i++)
{
if (properties[i] == null) throw new ArgumentNullException("properties[" + i.ToString() + "]" );
_properties[properties[i].PName] = i;
_types[i] = properties[i].PType;
}
}

public string Name {get; private set;}

public int Count { get { return _values.Length; } }

private Dictionary<string, int> _properties;
private object[] _values;
private NpgsqlDbType[] _types;

public object this[int index]
{
get {
if (index < 0 || index > (_values.Length - 1)) throw new IndexOutOfRangeException(index.ToString());

return _values[index];
}
set {
if (index < 0 || index > (_values.Length - 1)) throw new IndexOutOfRangeException(index.ToString());
/*
TODO: need verify type of 'value' by '_types[index]' and switch statement.
*/
_values[index] = value;
}
}

public object this[string index]
{
get {
if (index == null) throw new ArgumentNullException();
if (!_properties.ContainsKey(index)) throw new ArgumentOutOfRangeException(index);
return this[_properties[index]];
}
set {
if (index == null) throw new ArgumentNullException();
if (!_properties.ContainsKey(index)) throw new ArgumentOutOfRangeException(index);
this[_properties[index]] = value;
}
}
}
----------------------------------------------------------


For getting from DB need method:
reader.GetComposite(ref NpgsqlComposite cType)

Thank you.

Followup

No Followups Have Been Posted

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge