Esempio n. 1
0
 private static DatabaseUtility.Schema.ResultSet GetResultSet(DataTable resultSetSchemaInfo,String suffix)
 {
     var resultSet = new DatabaseUtility.Schema.ResultSet();
     resultSet.Name = "ResultSet" + suffix;
     for (int j = 0; j < resultSetSchemaInfo.Rows.Count; j++)
     {
         DatabaseUtility.Schema.DatabaseField field = new DatabaseUtility.Schema.DatabaseField();
         var dbType = (System.Data.SqlDbType) Convert.ToInt32(resultSetSchemaInfo.Rows[j]["ProviderType"]);
         field.Name = resultSetSchemaInfo.Rows[j]["ColumnName"].ToString();
         field.Type = DatabaseTypeMapping.SqlMapping[dbType];
         field.Ordinal = Convert.ToInt32(resultSetSchemaInfo.Rows[j]["ColumnOrdinal"]);
         field.Nullable = Convert.ToBoolean(resultSetSchemaInfo.Rows[j]["AllowDBNull"]);
         field.Size = Convert.ToInt32(resultSetSchemaInfo.Rows[j]["ColumnSize"]);
         resultSet.Columns.Add(field);
     }
     return resultSet;
 }
        private void Materialize(DatabaseSchema result, System.Data.SqlClient.SqlDataReader reader)
        {
            var sprocName = reader["StoredProcedureName"].ToString();
            var fieldName = reader["Name"].ToString();
            var isParameterStr = reader["IsParameter"].ToString();
            var resultSetName = reader["ResultSetName"].ToString();
            var direction = reader["ParameterDirection"].ToString();
            var dbType = reader["DatabaseType"].ToString();
            var ordinal = reader["Ordinal"].ToString();
            var nullable = reader["Nullable"].ToString();
            var size = reader["SIZE"].ToString();

            var sproc = (from sp in result.StoredProcedures where sp.Name == sprocName  select sp).SingleOrDefault();
            if (sproc == null)
            {
                sproc = new StoredProcedure() {Name = sprocName};
                result.StoredProcedures.Add(sproc);
            }

            Boolean isParameter = true;
            if(Boolean.TryParse(isParameterStr,out isParameter ) && isParameter)
            {
                var param = new DatabaseUtility.Schema.Parameter();
                param.Name = fieldName;
                param.Direction =
                    (DatabaseUtility.Schema.ParameterDirection)
                    Enum.Parse(typeof (DatabaseUtility.Schema.ParameterDirection), direction);
                param.Type =
                    (DatabaseUtility.Schema.DatabaseType)
                    Enum.Parse(typeof (DatabaseUtility.Schema.DatabaseType), dbType);
                param.Ordinal = Convert.ToInt32(ordinal);
                param.Nullable = Convert.ToBoolean(nullable);
                param.Size = Convert.ToInt32(size);

                sproc.Parameters.Add(param);
            }
            else if (Boolean.TryParse(isParameterStr, out isParameter) && !isParameter)
            {
                var resultSet = (from rs in sproc.ResultSets
                                 where rs.Name == resultSetName
                                 select rs).SingleOrDefault();
                if (resultSet == null)
                {
                    resultSet = new ResultSet() { Name = resultSetName };
                    sproc.ResultSets.Add(resultSet);
                }

                var resultSetColumn = new DatabaseUtility.Schema.DatabaseField();
                resultSetColumn.Name = fieldName;
                resultSetColumn.Type =
                    (DatabaseUtility.Schema.DatabaseType)
                    Enum.Parse(typeof(DatabaseUtility.Schema.DatabaseType), dbType);
                resultSetColumn.Ordinal = Convert.ToInt32(ordinal);
                resultSetColumn.Nullable = Convert.ToBoolean(nullable);
                resultSetColumn.Size = Convert.ToInt32(size);

                resultSet.Columns.Add(resultSetColumn);
            }
        }