• 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
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

People who like this

0 Show 0
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

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

People who like this

0 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

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

why sqlite can't conneted after build in PC (.exe) 0 Answers

how to access and modify my existing database made by DB browser for SQLite in unity after build 0 Answers

how to use database in unity for developing android games? 0 Answers

SqliteException: Unable to open the database file - Ready-made DB Provided To Access 0 Answers

script does not update inspector? 3 Answers


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