Exemple #1
0
        ////Select statement
        public List <twitter.Models.TweetsModel> Select(string strQuery)
        {
            List <twitter.Models.TweetsModel> rtnResponse = new List <twitter.Models.TweetsModel>();

            try
            {
                //open connection
                if (this.OpenConnection() == true)
                {
                    //create command and assign the query and connection from the constructor
                    MySqlCommand cmd = new MySqlCommand();

                    cmd.Connection  = connection;
                    cmd.CommandText = strQuery;
                    cmd.CommandType = CommandType.StoredProcedure;

                    //Execute command
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            twitter.Models.TweetsModel tweetModel = new twitter.Models.TweetsModel();
                            tweetModel.searchTerm1      = reader.GetString(reader.GetOrdinal("searchTerm1")).ToString();
                            tweetModel.searchTermCount1 = int.Parse(reader.GetString(reader.GetOrdinal("searchTerm1Count")));
                            tweetModel.searchTerm2      = reader.GetString(reader.GetOrdinal("searchTerm2")).ToString();
                            tweetModel.searchTermCount2 = int.Parse(reader.GetString(reader.GetOrdinal("searchTerm2Count")));
                            rtnResponse.Add(tweetModel);
                        }
                    }

                    //close connection
                    this.CloseConnection();
                }

                return(rtnResponse);
            }
            catch (Exception ex)
            {
                //Need to send this to a log
                string strError = "";
                strError = ex.ToString();

                rtnResponse = new List <twitter.Models.TweetsModel>();
                return(rtnResponse);
            }
        }
Exemple #2
0
        ////Select statement
        public List <twitter.Models.TweetsModel> Select(string strQuery)
        {
            List <twitter.Models.TweetsModel> rtnResponse = new List <twitter.Models.TweetsModel>();

            try
            {
                //open connection
                if (this.OpenConnection() == true)
                {
                    //create command and assign the query and connection from the constructor
                    MySqlCommand cmd = new MySqlCommand();

                    cmd.Connection  = connection;
                    cmd.CommandText = strQuery;
                    cmd.CommandType = CommandType.StoredProcedure;

                    //Execute command
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            twitter.Models.TweetsModel tweetModel = new twitter.Models.TweetsModel();
                            tweetModel.searchTerm1      = "";
                            tweetModel.searchTermCount1 = 0;
                            tweetModel.searchTerm2      = "";
                            tweetModel.searchTermCount2 = 0;
                            tweetModel.proximity        = "";
                            tweetModel.addressFrom      = "";
                            tweetModel.avgTermsPerHour1 = 0;
                            tweetModel.avgTermsPerHour2 = 0;
                            tweetModel.avgTermsPerMin1  = 0;
                            tweetModel.avgTermsPerMin2  = 0;

                            if (!reader.IsDBNull(reader.GetOrdinal("searchTerm1")))
                            {
                                tweetModel.searchTerm1 = reader.GetString(reader.GetOrdinal("searchTerm1")).ToString();
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("searchTerm1Count")))
                            {
                                tweetModel.searchTermCount1 = int.Parse(reader.GetString(reader.GetOrdinal("searchTerm1Count")));
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("searchTerm2")))
                            {
                                tweetModel.searchTerm2 = reader.GetString(reader.GetOrdinal("searchTerm2")).ToString();
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("searchTerm2Count")))
                            {
                                tweetModel.searchTermCount2 = int.Parse(reader.GetString(reader.GetOrdinal("searchTerm2Count")));
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("proximity")))
                            {
                                tweetModel.proximity = reader.GetString(reader.GetOrdinal("proximity")).ToString();
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("addressFrom")))
                            {
                                tweetModel.addressFrom = reader.GetString(reader.GetOrdinal("addressFrom")).ToString();
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("avgTermsPerHour1")))
                            {
                                tweetModel.avgTermsPerHour2 = int.Parse(reader.GetString(reader.GetOrdinal("avgTermsPerHour2")));
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("avgTermsPerMin1")))
                            {
                                tweetModel.avgTermsPerMin1 = int.Parse(reader.GetString(reader.GetOrdinal("avgTermsPerMin1")));
                            }
                            if (!reader.IsDBNull(reader.GetOrdinal("avgTermsPerMin2")))
                            {
                                tweetModel.avgTermsPerMin2 = int.Parse(reader.GetString(reader.GetOrdinal("avgTermsPerMin2")));
                            }
                            rtnResponse.Add(tweetModel);
                        }
                    }

                    //close connection
                    this.CloseConnection();
                }

                return(rtnResponse);
            }
            catch (Exception ex)
            {
                //Need to send this to a log
                string strError = "";
                strError = ex.ToString();

                rtnResponse = new List <twitter.Models.TweetsModel>();
                TweetsModel tweetModel = new TweetsModel();

                tweetModel.strError += "Error Occured Select tweets: " + strError;

                rtnResponse.Add(tweetModel);
                return(rtnResponse);
            }
        }