Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Strangerweather · Mar 31, 2016 at 08:00 AM · androidscripting problemerrordatabasesqlite

Help with SQLite for Android Errors in Unity3D?

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>(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! :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mrland · Apr 01, 2016 at 02:12 PM

Hello! facebook corner of the edit settings button. you can change at that place

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Strangerweather · Apr 01, 2016 at 05:55 PM 0
Share

Hi! I don't actually understand your answer. What do you mean? :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SQLite Transaction Update Problem on Android 0 Answers

SqlLite , android and unity 1 Answer

Unity sqlite to android: no such table 0 Answers

Sqlite3.dll not found on specific Android devices 2 Answers

Sqlite3.dll not integrated into Android Build 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges