Esempio n. 1
0
 private ScopeTableCollection ExtractSchema(string[] schemaList)
 {
     var tablesInfo = new ScopeTableCollection();
     var extractSchema = SqlTemplate.Get("ExtractSchema");
     using (var con = new SqlConnection(_request.ConnectionString))
     {
         using (var cmd = new SqlCommand())
         {
             con.Open();
             foreach (var sequence in schemaList)
             {
                 try
                 {
                     cmd.Parameters.Clear();
                     cmd.Connection = con;
                     cmd.CommandText = extractSchema;
                     cmd.CommandType = CommandType.Text;
                     cmd.Parameters.Add("@objname", SqlDbType.NVarChar).Value = sequence;
                     ScopeColumnCollection tableInfo;
                     using (var reader = cmd.ExecuteReader())
                     {
                         tableInfo = new ScopeColumnCollection();
                         if (!reader.HasRows)
                             throw new Exception($"Table {sequence} does not exists.");
                         while (reader.Read())
                         {
                             tableInfo.Add(new ScopeColumn
                             {
                                 Name = reader.GetString(0),
                                 Type = Runtime.GetType(reader.GetString(1)),
                                 Length = reader.GetInt32(2),
                                 Primary = Runtime.CheckInternalKey(_request.CustomKeyDefinitions, sequence, reader.GetString(0), reader.GetBoolean(4))
                             });
                         }
                     }
                     var primaryExists = (from ScopeColumn ci in tableInfo where ci.Primary select ci.Primary).FirstOrDefault();
                     if (primaryExists)
                         tablesInfo.Add(new ScopeTable { Name = sequence, Columns = tableInfo });
                     else
                     {
                         if (!_skipList.ContainsKey(sequence))
                         {
                             _skipList.Add(sequence, "Table needs primary key or clustered index.");
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     if (!_skipList.ContainsKey(sequence))
                     {
                         _skipList.Add(sequence, ex.ToString());
                     }
                 }
             }
         }
         _scopeDescription = tablesInfo;
         return tablesInfo;
     }
 }
Esempio n. 2
0
        private ScopeTableCollection ExtractSchema(string[] schemaList)
        {
            var tablesInfo    = new ScopeTableCollection();
            var extractSchema = SqlTemplate.Get("ExtractSchema");

            using (var con = new SqlConnection(_request.ConnectionString))
            {
                using (var cmd = new SqlCommand())
                {
                    con.Open();
                    foreach (var sequence in schemaList)
                    {
                        try
                        {
                            cmd.Parameters.Clear();
                            cmd.Connection  = con;
                            cmd.CommandText = extractSchema;
                            cmd.CommandType = CommandType.Text;
                            cmd.Parameters.Add("@objname", SqlDbType.NVarChar).Value = sequence;
                            ScopeColumnCollection tableInfo;
                            using (var reader = cmd.ExecuteReader())
                            {
                                tableInfo = new ScopeColumnCollection();
                                if (!reader.HasRows)
                                {
                                    throw new Exception($"Table {sequence} does not exists.");
                                }
                                while (reader.Read())
                                {
                                    tableInfo.Add(new ScopeColumn
                                    {
                                        Name    = reader.GetString(0),
                                        Type    = Runtime.GetType(reader.GetString(1)),
                                        Length  = reader.GetInt32(2),
                                        Primary = Runtime.CheckInternalKey(_request.CustomKeyDefinitions, sequence, reader.GetString(0), reader.GetBoolean(4))
                                    });
                                }
                            }
                            var primaryExists = (from ScopeColumn ci in tableInfo where ci.Primary select ci.Primary).FirstOrDefault();
                            if (primaryExists)
                            {
                                tablesInfo.Add(new ScopeTable {
                                    Name = sequence, Columns = tableInfo
                                });
                            }
                            else
                            {
                                if (!_skipList.ContainsKey(sequence))
                                {
                                    _skipList.Add(sequence, "Table needs primary key or clustered index.");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (!_skipList.ContainsKey(sequence))
                            {
                                _skipList.Add(sequence, ex.ToString());
                            }
                        }
                    }
                }
                _scopeDescription = tablesInfo;
                return(tablesInfo);
            }
        }