Esempio n. 1
0
        public void RunSQL(SQL_Query sqlQuery)
        {
            string          connectionstring;
            MySqlConnection cnn    = null;
            MySqlDataReader reader = null;

            connectionstring = "server=" + sqlQuery.Server + ";database=" + sqlQuery.Database + ";uid=" + sqlQuery.User + ";pwd=" + sqlQuery.Psw;
            Console.WriteLine("Connection string: " + connectionstring);
            cnn = new MySqlConnection(connectionstring);
            try
            {
                OnProgressUpdate?.Invoke(sqlQuery.JobId);
                cnn.Open();
                Console.WriteLine("Connection Open");

                string query = "select * from arkiv";

                MySqlCommand cmd = new MySqlCommand(sqlQuery.Query, cnn);
                reader = cmd.ExecuteReader();

                int    ColumnCount   = reader.FieldCount;
                string ListOfColumns = string.Empty;

                while (reader.Read())
                {
                    for (int i = 0; i < ColumnCount; i++)
                    {
                        ListOfColumns = ListOfColumns + reader[i].ToString() + "|";
                    }
                    ListOfColumns = ListOfColumns + "\r\n";
                }

                sqlQuery.Result = ListOfColumns;
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Unable to open connection!");

                throw ex;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                if (cnn != null)
                {
                    cnn.Close();
                    Console.WriteLine("Connection Closed");
                }
            }
        }
Esempio n. 2
0
        // Reads SQL queries from queryInfoList into SQL_Query object.
        public void MakeSQLQuery(List <string> queryInfoList)
        {
            SQL_Query sqlQuery = new SQL_Query();

            SqlQueryList.Add(sqlQuery);
            sqlQuery.JobId          = queryInfoList[1].Split('=')[1];
            sqlQuery.JobEnabled     = queryInfoList[2].Split('=')[1];
            sqlQuery.JobName        = queryInfoList[3].Split('=')[1].Trim();
            sqlQuery.JobDescription = queryInfoList[4].Split('=')[1].Trim();
            sqlQuery.System         = queryInfoList[6].Split('=')[1];
            sqlQuery.SubSystem      = queryInfoList[7].Split('=')[1];
            sqlQuery.Source         = queryInfoList[8].Split('=')[1];
            sqlQuery.Target         = queryInfoList[9].Split('=')[1];

            sqlQuery.Server   = queryInfoList[11].Split('=')[1];
            sqlQuery.Database = queryInfoList[12].Split('=')[1];
            sqlQuery.User     = queryInfoList[13].Split('=')[1];
            sqlQuery.Psw      = queryInfoList[14].Split('=')[1];
            sqlQuery.Query    = queryInfoList[17];
        }