Example #1
0
        private void QuerySelect()
        {
            DataTable sqlresponse = new DataTable();


            ssh.Connect();
            SelectOutput selectOutput = ssh.SelectFromTable(Table, txtWhere.Text, txtOrder.Text, txtLimit.Text);


            dataGridView1.DataSource = selectOutput.Table;
            PrimaryKeyData           = selectOutput.PrimaryKey;
            ssh.Disconnect();

            UpdateList.Clear();
            InsertList.Clear();

            InitialRowsCount = dataGridView1.Rows.Count;
        }
Example #2
0
        public SelectOutput SelectFromTable(string table,
                                            String whereCondition,
                                            String order,
                                            String limit
                                            )
        {
            String columnList = "";


            DescribeOutput describe     = Describe(table);
            DataTable      outputTable  = new DataTable();
            SelectOutput   selectOutput = new SelectOutput();

            foreach (DBColumn column in describe.Columns)
            {
                columnList += column.ColumnName + ", ";
                outputTable.Columns.Add(column.ColumnName);
            }

            columnList = columnList.Trim().TrimEnd(',');
            if (!string.IsNullOrEmpty(whereCondition))
            {
                whereCondition = "WHERE " + whereCondition;
            }
            if (!string.IsNullOrEmpty(order))
            {
                order = "ORDER BY " + order;
            }
            if (!string.IsNullOrEmpty(limit))
            {
                limit = "LIMIT " + limit;
            }
            String writeCommand = String.Format("echo \"SELECT {0} FROM {1} {2} {3} {4};\" > {5}", columnList, table, whereCondition, order, limit, SqlFile);
            var    response     = sshClient.RunCommand(writeCommand);

            response = sshClient.RunCommand(PsqlScriptExec());

            int counter = 0;

            foreach (String line in response.Result.Split('\n'))
            {
                if (counter > 1)
                {
                    string[] listOfData = line.Split('|');
                    if (listOfData.Length > 1)
                    {
                        DataRow r = outputTable.NewRow();
                        int     i = 0;
                        foreach (DataColumn column in outputTable.Columns)
                        {
                            r[column.ColumnName] = listOfData[i].Trim();
                            i++;
                        }

                        outputTable.Rows.Add(r);
                    }
                }
                counter++;
            }

            selectOutput.Table      = outputTable;
            selectOutput.PrimaryKey = describe.PrimaryKey;
            return(selectOutput);
        }