Beispiel #1
0
 private bool ExistColumn(DescribeOutput destinationTabDescription, DBColumn dbColumn)
 {
     foreach (DBColumn destColumn in destinationTabDescription.Columns)
     {
         if (destColumn.ColumnName.Equals(dbColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
        public DescribeOutput Describe(string tableName)
        {
            var             response        = sshClient.RunCommand(PsqlInlineCommand(String.Format("\\d {0}", tableName)));
            DescribeOutput  output          = new DescribeOutput();
            List <DBColumn> describeColumns = new List <DBColumn>();

            output.TableName = tableName;
            int    rowCounter = 0;
            string primaryKey = "";

            foreach (String line in response.Result.Split('\n'))
            {
                output.RawText += line + System.Environment.NewLine;
                if (rowCounter > 1)
                {
                    string[] spltArg = line.Split('|');
                    if (spltArg.Length > 1)
                    {
                        DBColumn newColumn = new DBColumn();
                        newColumn.ColumnName = spltArg[0].Trim();
                        newColumn.Type       = spltArg[1].Trim();
                        if (spltArg.Length > 2)
                        {
                            newColumn.Modifiers = spltArg[2].Trim();
                        }
                        describeColumns.Add(newColumn);
                    }
                    else
                    {
                        if (line.Trim().ToUpper().Contains("PRIMARY KEY,"))
                        {
                            string[] keyval = line.Split('(');
                            primaryKey = keyval[1].TrimEnd(')');
                        }
                    }
                }
                rowCounter++;
            }

            output.Columns = describeColumns;
            output.SetPrimaryKey(primaryKey);
            return(output);
        }