Пример #1
0
        protected override IEnumerable <DatabaseModel.ProcedureParameter> GetStoredProcedureParametersUnordered(IDbConnection connection, string domain, string storedProcedureName)
        {
            using (DataTable dt = ((OdbcConnection)connection).GetSchema("ProcedureParameters", new string[] { null, domain, storedProcedureName }))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    var parameter = new DatabaseModel.ProcedureParameter
                    {
                        Name       = dr["COLUMN_NAME"].ToString(),
                        DataType   = DatabaseModel.ParseDataType(dr["TYPE_NAME"].ToString()),
                        Precision  = dr["DECIMAL_DIGITS"] == DBNull.Value ? (int?)null : (short)dr["DECIMAL_DIGITS"],
                        Scale      = dr["NUM_PREC_RADIX"] == DBNull.Value ? (int?)null : (short)dr["NUM_PREC_RADIX"],
                        Size       = dr["COLUMN_SIZE"] == DBNull.Value ? (int?)null : (int)dr["COLUMN_SIZE"],
                        IsNullable = dr["IS_NULLABLE"].ToString() == "YES",
                        Position   = (int)dr["ORDINAL_POSITION"]
                    };
                    switch ((short)dr["COLUMN_TYPE"])
                    {
                    case 1: parameter.Direction = DatabaseModel.ParameterDirection.In; break;

                    case 2: parameter.Direction = DatabaseModel.ParameterDirection.InOut; break;

                    case 3: parameter.Direction = DatabaseModel.ParameterDirection.Out; break;

                    case 5: parameter.Direction = DatabaseModel.ParameterDirection.ReturnValue; break;
                    }
                    yield return(parameter);
                }
            }
        }
Пример #2
0
        protected override IEnumerable <DatabaseModel.ProcedureParameter> GetStoredProcedureParametersUnordered(IDbConnection connection, string domain, string storedProcedureName)
        {
            using (DataTable dt = ((OleDbConnection)connection).GetOleDbSchemaTable(OleDbSchemaGuid.Procedure_Parameters, new object[] { null, domain, storedProcedureName }))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    var parameter = new DatabaseModel.ProcedureParameter
                    {
                        Name       = dr["PARAMETER_NAME"].ToString(),
                        DataType   = DatabaseModel.ParseDataType(dr["TYPE_NAME"].ToString()),
                        Precision  = dr["NUMERIC_PRECISION"] == DBNull.Value ? (int?)null : (int)dr["NUMERIC_PRECISION"],
                        Scale      = dr["NUMERIC_SCALE"] == DBNull.Value ? (int?)null : (short)dr["NUMERIC_SCALE"],
                        Size       = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? (int?)null : dr["CHARACTER_MAXIMUM_LENGTH"] is decimal ? (int)(decimal)dr["CHARACTER_MAXIMUM_LENGTH"] : (int)(long)dr["CHARACTER_MAXIMUM_LENGTH"],
                        IsNullable = (bool)dr["IS_NULLABLE"],
                        Position   = (int)dr["ORDINAL_POSITION"]
                    };
                    switch ((int)dr["PARAMETER_TYPE"])
                    {
                    case 1: parameter.Direction = DatabaseModel.ParameterDirection.In; break;

                    case 2: parameter.Direction = DatabaseModel.ParameterDirection.InOut; break;

                    case 3: parameter.Direction = DatabaseModel.ParameterDirection.Out; break;

                    case 4: parameter.Direction = DatabaseModel.ParameterDirection.ReturnValue; break;
                    }
                    yield return(parameter);
                }
            }
        }
Пример #3
0
        protected override IEnumerable <DatabaseModel.ProcedureParameter> GetStoredProcedureParametersUnordered(IDbConnection connection, string domain, string storedProcedureName)
        {
            yield return(new DatabaseModel.ProcedureParameter
            {
                Name = "@RETURN_VALUE",
                Direction = DatabaseModel.ParameterDirection.ReturnValue,
                DataType = DatabaseModel.DataType.Int32
            });

            using (DataTable dt = ((SqlConnection)connection).GetSchema("ProcedureParameters", new string[] { null, domain, storedProcedureName }))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int?scale = dr["NUMERIC_SCALE"] == DBNull.Value ? (int?)null : (int)dr["NUMERIC_SCALE"];
                    yield return(new DatabaseModel.ProcedureParameter
                    {
                        Name = dr["PARAMETER_NAME"].ToString(),
                        Direction = (DatabaseModel.ParameterDirection)Enum.Parse(typeof(DatabaseModel.ParameterDirection), dr["PARAMETER_MODE"].ToString(), true),
                        DataType = DatabaseModel.ParseDataType(dr["DATA_TYPE"].ToString(), scale ?? 0),
                        Precision = dr["NUMERIC_PRECISION"] == DBNull.Value ? (int?)null : (byte)dr["NUMERIC_PRECISION"],
                        Scale = scale,
                        Size = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? (int?)null : (int)dr["CHARACTER_MAXIMUM_LENGTH"],
                        IsNullable = false,
                        Position = (int)dr["ORDINAL_POSITION"]
                    });
                }
            }
        }
Пример #4
0
 protected override IEnumerable <DatabaseModel.Column> GetTableColumns(IDbConnection connection, string domain, string tableName)
 {
     using (DataTable dt = ((OdbcConnection)connection).GetSchema("Columns", new string[] { null, domain, tableName }))
     {
         foreach (DataRow dr in dt.Rows)
         {
             yield return(new DatabaseModel.Column
             {
                 Name = dr["COLUMN_NAME"].ToString(),
                 DataType = DatabaseModel.ParseDataType(dr["TYPE_NAME"].ToString()),
                 Precision = dr["DECIMAL_DIGITS"] == DBNull.Value ? (int?)null : (short)dr["DECIMAL_DIGITS"],
                 Scale = dr["NUM_PREC_RADIX"] == DBNull.Value ? (int?)null : (short)dr["NUM_PREC_RADIX"],
                 Size = dr["COLUMN_SIZE"] == DBNull.Value ? (int?)null : (int)dr["COLUMN_SIZE"],
                 IsNullable = dr["IS_NULLABLE"].ToString() == "YES"
             });
         }
     }
 }
Пример #5
0
 protected override IEnumerable <DatabaseModel.Column> GetTableColumns(IDbConnection connection, string domain, string tableName)
 {
     using (DataTable dt = ((OracleConnection)connection).GetSchema("Columns", new string[] { domain, tableName }))
     {
         foreach (DataRow dr in dt.Rows)
         {
             int?scale = dr["SCALE"] == DBNull.Value ? (int?)null : (int)(decimal)dr["SCALE"];
             yield return(new DatabaseModel.Column
             {
                 Name = dr["COLUMN_NAME"].ToString(),
                 DataType = DatabaseModel.ParseDataType(dr["DATATYPE"].ToString(), scale ?? 0),
                 Precision = dr["PRECISION"] == DBNull.Value ? (int?)null : (int)(decimal)dr["PRECISION"],
                 Scale = scale,
                 Size = dr["LENGTH"] == DBNull.Value ? (int?)null : (int)(decimal)dr["LENGTH"],
                 IsNullable = dr["NULLABLE"].ToString() == "Y"
             });
         }
     }
 }
Пример #6
0
 protected override IEnumerable <DatabaseModel.Column> GetTableColumns(IDbConnection connection, string domain, string tableName)
 {
     using (DataTable dt = ((SqlConnection)connection).GetSchema("Columns", new string[] { null, domain, tableName }))
     {
         foreach (DataRow dr in dt.Rows.OfType <DataRow>().OrderBy(row => Convert.ToInt32(row["ORDINAL_POSITION"])))
         {
             int?scale = dr["NUMERIC_SCALE"] == DBNull.Value ? (int?)null : (int)dr["NUMERIC_SCALE"];
             yield return(new DatabaseModel.Column
             {
                 Name = dr["COLUMN_NAME"].ToString(),
                 DataType = DatabaseModel.ParseDataType(dr["DATA_TYPE"].ToString(), scale ?? 0),
                 Precision = dr["NUMERIC_PRECISION"] == DBNull.Value ? (int?)null : (byte)dr["NUMERIC_PRECISION"],
                 Scale = scale,
                 Size = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? (int?)null : (int)dr["CHARACTER_MAXIMUM_LENGTH"],
                 IsNullable = dr["IS_NULLABLE"].ToString() == "YES"
             });
         }
     }
 }
Пример #7
0
 protected override IEnumerable <DatabaseModel.ProcedureParameter> GetStoredProcedureParametersUnordered(IDbConnection connection, string owner, string storedProcedureName)
 {
     using (DataTable dt = ((OracleConnection)connection).GetSchema("ProcedureParameters", new string[] { owner, storedProcedureName }))
     {
         foreach (DataRow dr in dt.Rows)
         {
             int?scale = dr["DATA_SCALE"] == DBNull.Value ? (int?)null : (int)(decimal)dr["DATA_SCALE"];
             yield return(new DatabaseModel.ProcedureParameter
             {
                 Name = dr["ARGUMENT_NAME"].ToString(),
                 Direction = (DatabaseModel.ParameterDirection)Enum.Parse(typeof(DatabaseModel.ParameterDirection), dr["IN_OUT"].ToString().Replace("/", string.Empty), true),
                 DataType = DatabaseModel.ParseDataType(dr["DATA_TYPE"].ToString(), scale ?? 0),
                 Precision = dr["DATA_PRECISION"] == DBNull.Value ? (int?)null : (int)(decimal)dr["DATA_PRECISION"],
                 Scale = scale,
                 Size = dr["DATA_LENGTH"] == DBNull.Value ? (int?)null : (int)(decimal)dr["DATA_LENGTH"],
                 IsNullable = false,
                 Position = (int)(decimal)dr["POSITION"]
             });
         }
     }
 }
Пример #8
0
        protected override IEnumerable <DatabaseModel.Column> GetTableColumns(IDbConnection connection, string domain, string tableName)
        {
            var dataTypeMap = new Dictionary <int, string>();

            using (DataTable dt = ((OleDbConnection)connection).GetOleDbSchemaTable(OleDbSchemaGuid.Provider_Types, null))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int    dataType = (int)dr["DATA_TYPE"];
                    string typeName = dr["TYPE_NAME"].ToString();
                    if (dataTypeMap.ContainsKey(dataType))
                    {
                        dataTypeMap[dataType] = typeName;
                    }
                    else
                    {
                        dataTypeMap.Add(dataType, typeName);
                    }
                }
            }

            using (DataTable dt = ((OleDbConnection)connection).GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, domain, tableName }))
            {
                foreach (DataRow dr in dt.Rows)
                {
                    yield return(new DatabaseModel.Column
                    {
                        Name = dr["COLUMN_NAME"].ToString(),
                        DataType = DatabaseModel.ParseDataType(dataTypeMap[(int)dr["DATA_TYPE"]]),
                        Precision = dr["NUMERIC_PRECISION"] == DBNull.Value ? (int?)null : (int)dr["NUMERIC_PRECISION"],
                        Scale = dr["NUMERIC_SCALE"] == DBNull.Value ? (int?)null : (short)dr["NUMERIC_SCALE"],
                        Size = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? (int?)null : dr["CHARACTER_MAXIMUM_LENGTH"] is decimal ? (int)(decimal)dr["CHARACTER_MAXIMUM_LENGTH"] : (int)(long)dr["CHARACTER_MAXIMUM_LENGTH"],
                        IsNullable = (bool)dr["IS_NULLABLE"]
                    });
                }
            }
        }
Пример #9
0
 public ResultSets(System.Data.DataSet dataSet)
 {
     foreach (System.Data.DataTable nextTable in dataSet.Tables)
     {
         DatabaseModel.ResultSet nextResultSet = new DatabaseModel.ResultSet();
         foreach (System.Data.DataColumn nextColumn in nextTable.Columns)
         {
             nextResultSet.Fields.Add(new DatabaseModel.ResultSetField(nextColumn.ColumnName, DatabaseModel.ParseDataType(nextColumn.DataType)));
         }
         Add(nextResultSet);
     }
 }