public static Question[] ReadQuestions(string table_name) { List <Question> questions = new List <Question>(); string sql = "select * from Questions order by Question"; IDbConnection _connection; _connection = (IDbConnection) new SqliteConnection("URI=file:" + Application.dataPath + "/sampledb.sqlite"); _connection.Open(); IDbCommand IDbCommand = _connection.CreateCommand(); IDbCommand.CommandText = sql; IDataReader _reader = IDbCommand.ExecuteReader(); _connection.Close(); while (_reader.Read()) { //Debug.Log("Question: " + _reader["Question"] + "\t" + "Subject: " + _reader["Subject"]); Question quest = new Question(); quest.Text = _reader["Question"] as string; quest.AddSubject(_reader["Subject"] as string); quest.AddHint(_reader["Hint"] as string); quest.difficulty = (Difficulty)_reader["Difficulty"]; quest.AddAnswer(_reader["Answer 1"] as string); quest.AddAnswer(_reader["Answer 2"] as string); quest.AddAnswer(_reader["Answer 3"] as string); quest.AddAnswer(_reader["Answer 4"] as string); questions.Add(quest); } // // if (_command != null){ // _command.Dispose(); // _command = null; // } // if (_connection != null){ // _connection .Close(); // _connection = null; // } Debug.Log(questions.Count); return(questions.ToArray()); }
//private static List<string> subjects = new List<string>(); // // public static string[] Subjects{ // get{return subjects.ToArray();} // } // // public static void AddSubject(string subject){ // // if (!subjects.Contains(subject)) // subjects.Add (subject); // } // public static Question[] ReadQuestions(TextAsset content) { List <Question> questions = new List <Question>(); using (StringReader reader = new StringReader(content.text)) { Question new_question = null; // = new Question(); string current_subject = "Default"; Difficulty current_difficulty = Difficulty.Easy; string line; while ((line = reader.ReadLine()) != null) { string[] parts = line.Split(' '); for (int i = 0; i < parts.Length; i++) { if (parts[i] == "//") //|| parts[i] == "\t"){ { break; } // SET DIFFICULTY if ((parts[i] == "#D" || parts[i] == "\t#D") && new_question != null) { if (parts[i + 1] == "Easy") { current_difficulty = Difficulty.Easy; } else if (parts[i + 1] == "Medium") { current_difficulty = Difficulty.Medium; } else if (parts[i + 1] == "Hard") { current_difficulty = Difficulty.Hard; } } // ADD A NEW QUESTION if (parts[i] == "#Q" || parts[i] == "\t#Q") { new_question = new Question(); new_question.Text = ReadSentence(parts, i + 1); new_question.difficulty = current_difficulty; new_question.AddSubject(current_subject); questions.Add(new_question); //new_question.DoDebug(); } // ADD A NEW ANSWER if ((parts[i] == "#A" || parts[i] == "\t#A") && new_question != null) { new_question.AddAnswer(ReadSentence(parts, i + 1)); } // ADD A NEW HINT if ((parts[i] == "#H" || parts[i] == "\t#H") && new_question != null) { new_question.AddHint(ReadSentence(parts, i + 1)); } // ADD A NEW SUBJECT if ((parts[i] == "#S" || parts[i] == "\t#S")) { current_subject = ReadSentence(parts, i + 1); // string[] words = ReadWords(parts, i+1); // // foreach (string word in words){ // new_question.AddSubject(word); // //AddSubject (word); // } } } } } // foreach (Question q in questions) // q.DoDebug(); //questions[0].DoDebug(); return(questions.ToArray()); }