Shadowrun: Awakened 29 September 2011 - Build 871
GetRoutineBase.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Data;
00004 using System.Linq;
00005 using System.Text;
00006 
00007 using MySql.Data.MySqlClient;
00008 
00009 namespace RoutineAnalyzer
00010 {
00016     abstract class GetRoutineBase : RoutineBase
00017     {
00024         public GetRoutineBase(string sql)
00025             : base(sql)
00026         {
00027             SetupExtendedArguments();
00028         }
00029 
00034         DataTable ExecuteTestCall()
00035         {
00036             using (MySqlConnection connection = ParseHelper.CreateDbConnection())
00037             {
00038                 connection.Open();
00039                 using (MySqlCommand command = connection.CreateCommand())
00040                 {
00041                     //call the SPROC
00042                     command.CommandType = System.Data.CommandType.StoredProcedure;
00043                     command.CommandText = _name;
00044                     MySqlParameter param = new MySqlParameter();
00045                     //we use the first parameter because it reflects the ID used to call the SPROC
00046                     param.ParameterName = _params[0].Name;
00047                     param.Value = 1;
00048                     command.Parameters.Add(param);
00049                     //return the reader as a table
00050                     using (MySqlDataReader reader = command.ExecuteReader())
00051                     {
00052                         DataTable table = new DataTable();
00053                         table.Load(reader);
00054                         return table;
00055                     }
00056                 }
00057             }
00058         }
00059 
00063         void SetupExtendedArguments()
00064         {
00065             DataTable table = ExecuteTestCall();
00066             for (int i = 0; i < table.Columns.Count; ++i)
00067             {
00068                 DataColumn col = table.Columns[i];
00069                 string standInDeclaration = "out " + col.ColumnName + " INTEGER";
00070                 RoutineParamBase param = CreateRoutineParam(standInDeclaration, i + 1);
00071                 _params.Add(param);
00072             }
00073         }
00074     }
00075 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net