private IEnumerator DatabaseContains(string word, WVObject <bool?> result)
    {
        Debug.Log("Checking if db contains word " + word);

        using (MySqlCommand command = _connection.CreateCommand())
        {
            command.CommandText = "SELECT " + TABLE_WORD + " FROM " + TABLE_NAME +
                                  " WHERE " + TABLE_WORD + " = " + "'" + word + "'";

            System.IAsyncResult asyncResult = command.BeginExecuteReader();

            while (!asyncResult.IsCompleted)
            {
                yield return(null);
            }
            //Debug.Log(asyncResult.AsyncState);
            //Debug.Log(asyncResult.IsCompleted);
            try
            {
                MySqlDataReader data;
                using (data = command.EndExecuteReader(asyncResult))
                {
                    result.value = data.Read();
                    Debug.Log("DatabaseContains word '" + word + "': " + result.value.ToString());
                    //if (!data.IsClosed) data.Close();
                }
            }
            catch (System.InvalidOperationException e)
            {
                Debug.LogError(e.StackTrace);
                Debug.LogError(e.Message);
                Debug.Log(Connection.State.ToString());
            }
        }
    }
    /// <summary>
    /// Gets a word and EmotionIdeal associated with it. This assumes that
    /// the database contains the word!
    /// </summary>
    /// <param name="word">Word to search for</param>
    /// <returns>WordAndEmoIdeal -- struct containing string and emotion ideal</returns>
    private IEnumerator GetWord(string word, WVObject <WordAndEmoIdeal> result)
    {
        Debug.Log("Getting word " + word + " from db");
        //WVObject<WordAndEmoIdeal> result = new WVObject<WordAndEmoIdeal>(word);

        WVObjectList_WordAndEmoIdeal.Add(result);

        WordAndEmoIdeal wordEmoIdeal = new WordAndEmoIdeal();

        using (MySqlCommand command = _connection.CreateCommand())
        {
            command.CommandText = "SELECT " + TABLE_WORD + ", " + TABLE_EMO_IDEAL + " FROM " + TABLE_NAME +
                                  " WHERE " + TABLE_WORD + " = " + "'" + word + "'";

            System.IAsyncResult asyncResult = command.BeginExecuteReader(System.Data.CommandBehavior.CloseConnection);

            Debug.Log("Connection before command: " + Connection.State.ToString());

            while (!asyncResult.IsCompleted)
            {
                yield return(null);
            }
            try
            {
                MySqlDataReader data;
                using (data = command.EndExecuteReader(asyncResult))
                {
                    //Debug.LogWarning("before data.Read()");
                    while (data.Read())
                    {
                        string w = (string)data[TABLE_WORD];
                        EmotionModel.EmotionIdeal emoIdeal = (EmotionModel.EmotionIdeal)
                                                             System.Enum.Parse(typeof(EmotionModel.EmotionIdeal),
                                                                               data[TABLE_EMO_IDEAL].ToString());

                        wordEmoIdeal.word    = w;
                        wordEmoIdeal.emoEnum = emoIdeal;

                        result.value = wordEmoIdeal;//at this point, since it's not null, we set it!
                        //Debug.LogWarning("reading data");
                    }
                    Debug.LogWarning("Data.isClosed = " + data.IsClosed.ToString());
                    //if (!data.IsClosed) data.Close();
                }
                //Debug.LogWarning("Data.isClosed AFTER using: " + data.IsClosed.ToString());

                //Debug.Log("Connection after everything: " + Connection.State.ToString());
            }
            catch (System.InvalidOperationException e)
            {
                Debug.LogError(e.StackTrace);
                Debug.LogError(e.Message);
                Debug.Log(Connection.State);
            }
        }
    }
    public static void AddEntry(string word, EmotionModel.EmotionIdeal emotionIdeal)
    {
        //We create the WVObject, and pass it to the coroutine
        WVObject <bool?> result = new WVObject <bool?>(word);

        Request newRequest = new Request();

        newRequest.type         = RequestType.Add;
        newRequest.word         = word;
        newRequest.emotionIdeal = emotionIdeal;
        newRequest.boolResult   = result;

        Instance.RequestQueue.Enqueue(newRequest);
    }
    public static WVObject <WordAndEmoIdeal> GetWordFromDatabase(string word)
    {
        //We create the WVObject, and pass it to the coroutine
        WVObject <WordAndEmoIdeal> result = new WVObject <WordAndEmoIdeal>(word);

        Request newRequest = new Request();

        newRequest.type = RequestType.Get;
        newRequest.word = word;
        newRequest.wordEmoIdealResult = result;

        Instance.RequestQueue.Enqueue(newRequest);

        return(result);
    }
    public static WVObject <bool?> DatabaseContainsEntry(string word)
    {
        //We create the WVObject, and pass it to the coroutine
        WVObject <bool?> result = new WVObject <bool?>(word);

        Request newRequest = new Request();

        newRequest.type       = RequestType.Contains;
        newRequest.word       = word;
        newRequest.boolResult = result;

        Instance.RequestQueue.Enqueue(newRequest);

        return(result);
    }
        // can directly compare a WVObject to a string!
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj is string)
            {
                return(WordName == obj);
            }

            if (obj is WVObject <T> )
            {
                WVObject <T> other = (WVObject <T>)obj;
                return(WordName == other.WordName && value.Equals(value));
            }
            return(false);
        }
    /// <summary>
    /// Raw write-to function for adding a string and EmotionIdeal to the database.
    /// This assumes that word is not too long (> 30 chars).
    /// </summary>
    /// <param name="word">The string to enter as the word</param>
    /// <param name="emotionIdeal">The emotion ideal to associate with word</param>
    private IEnumerator AddEntryToDatabase(string word, EmotionModel.EmotionIdeal emotionIdeal, WVObject <bool?> result)
    {
        Debug.Log("Adding entry " + word + " to db");
        using (MySqlCommand command = _connection.CreateCommand())
        {
            command.CommandText = "INSERT INTO " + TABLE_NAME + "(" + TABLE_WORD + ", " + TABLE_EMO_IDEAL + ")" +
                                  " VALUES" + "('" + word + "', " + "'" + ((int)emotionIdeal).ToString() + "');";

            System.IAsyncResult asyncResult = command.BeginExecuteNonQuery();

            while (!asyncResult.IsCompleted)
            {
                yield return(null);
            }

            command.EndExecuteNonQuery(asyncResult);

            result.value = true;
        }
    }