- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
private object[] select ( string tablename, Type type, string addict )
{
object[] returned_objects = new object[0];
string sql = "SELECT ";
sql += this.buildFieldNames( type );
sql += " FROM `" + tablename + "`" + addict;
MySqlDataReader reader = this.TryQueryReader( sql );
while (reader.Read( ))
{
var obj = Activator.CreateInstance( type );
FieldInfo[] fields = type.GetFields( );
foreach (FieldInfo finfo in fields)
{
if (finfo.FieldType == typeof( int ))
{
finfo.SetValue( obj, reader.GetInt32( finfo.Name ) );
}
else if (finfo.FieldType == typeof( bool ))
{
if (reader.GetString( finfo.Name ).Equals( "true" ))
{
finfo.SetValue( obj, true );
}
else
{
finfo.SetValue( obj, false );
}
}
else if (finfo.FieldType == typeof( float ))
{
finfo.SetValue( obj, reader.GetFloat( finfo.Name ) );
}
else if (finfo.FieldType == typeof( double ))
{
finfo.SetValue( obj, reader.GetDouble( finfo.Name ) );
}
else if (finfo.FieldType == typeof( string ))
{
finfo.SetValue( obj, reader.GetString( finfo.Name ) );
}
}
provider.IncreaseLength( ref returned_objects, 1 );
returned_objects.SetValue( obj, returned_objects.Length - 1 );
}
reader.Close( );
return returned_objects;
}