Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Help with SQLite for Android Errors in Unity3D?

$
0
0
Hi guys! I am trying to adapt a script to work with SQLite4Unity3D but I am struggling with 3 errors. I was wondering if anyone could help. Here is the script. I have adapted it as far as I could: using UnityEngine; using SQLite4Unity3d; using System; public class QuizStart : MonoBehaviour { private SQLiteConnection connection; private int[] rowIndices; private int questionIndex; void Start() { // Initialization string connectionString = "URI=file:" + Application.dataPath + "/quizz.db"; connection = (SQLiteConnection)new SQLiteConnection(connectionString); connection.Open(); InitializeQuestions(); // Execute GetNextQuestion when you need to access the next question GetNextQuestion(); } void OnDestroy() { connection.Close(); } private void InitializeQuestions() { // Retrieve amount of questions SQLiteCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM english"; var count = (Int64)cmd.ExecuteScalar(); // Generate a shuffled array of question indices. rowIndices = new int[count]; for (int i = 0; i < count; i++) rowIndices[i] = i; Shuffle(rowIndices); } public void GetNextQuestion() { // Read question from database. Do note that you'll have to use your own columns here. SQLiteCommand dbcmd = connection.CreateCommand(); string sqlQuery = string.Format("SELECT * " + "FROM english LIMIT 1 OFFSET {0}", rowIndices[questionIndex]); dbcmd.CommandText = sqlQuery; using (IDataReader reader = dbcmd.ExecuteReader()) { reader.Read(); string question = reader.GetString(1); Debug.Log("question: " + question); reader.Close(); } questionIndex++; if (questionIndex > rowIndices.Length) questionIndex = 0; } private static void Shuffle(T[] array) { var rnd = new System.Random(); int n = array.Length; while (n > 1) { int k = rnd.Next(n--); T temp = array[n]; array[n] = array[k]; array[k] = temp; } } } My 3 errors are with : CreateCommand() ll. 34 and 47/ ExecuteScalar l. 36/ IDataReader l. 51 Thanks for any help! :)

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>