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 UnityDev0008 · May 24, 2011 at 10:32 PM · c#sqlite

sqlite in unity indie version C#

Hey guys,

I have been trying to setup a sqlite server for my game, however I am running into problems with the Using statements (Using System.Data) in particular....Ive read around on old posts and they all say it works in JS but not C# so i was wondering if there is a way to get it to work in C#

Thanks in advanced!

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

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by by0log1c · Sep 11, 2012 at 12:51 AM

Using Sqlite within Unity really isn't that hard, while they can help, I really don't think third-party solutions are required. I'm pretty sure that the System.Data.Sqlite library works with C#, though my own implementation use Mono.Data.Sqlite, I can't remember if I had run into problem or if that's just a coincidence. In any case, Mono.Data.Sqlite.dll can be found in the Unity folder: C:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\2.0.

That'll make a messy post and uncleaned code, but here's an small wrapper I extracted from a project I have somewhere. Do not use it as actual implementation, its just for you to get an idea of how it works, I've removed all goodies and safe-checks for clarity. Finally, I did modify it a little, but I'm confident it works, I've used SQLite in that manner in several standalone games.

 using System;
 using System.Collections.Generic;
 using Mono.Data.Sqlite;
 
 public class SqliteWrapper
 {
     private SqliteConnection db = null;
 
     public void OpenDatabase(string path)
     {
         db = new SqliteConnection("URI=file:" + path);
         db.Open();
     }
 
     public void CloseDatabase()
     {
         db.Close();
         db = null;
     }

     //ugly get/set query method - sigh, yes I did use that...
     public object[] QueryDatabase(string query, bool isReadQuery = false)
     {
         var dbcmd = db.CreateCommand();
         dbcmd.CommandText = query;
         var reader = dbcmd.ExecuteReader();
 
         object[] output = null;
 
         if (isReadQuery)
         {
             int current = 0;
             var values = new List<object>();
             while (reader.Read())
                 values.Add(reader.GetValue(current++));
 
             output = values.ToArray();
         }
 
         return output;
     }
 }

By the way, SQLite doesn't require a server of any kind, it really boils down to database file.

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 by0log1c · Sep 11, 2012 at 05:05 AM 0
Share

As for the webplayer, one could hack around the problem by using PHP's native support for SQLite and $$anonymous$$ySQL, passing the data with WWW or even ExternalCall.

avatar image
0

Answer by Bunny83 · May 24, 2011 at 11:10 PM

Do you use the official version from this page? Also you don't need / should not use the System.data namespace. You just need System.Data.SQLite. I don't believe that it works in JS and not in C#. Both are compiled to .Net/mono.

I haven't used it yet, but maybe i give it a try. I only used mysql in the past. SQLite only in C++ ;). But in Unity i wasn't in need of a database (well we have one but on the webserver...).

Comment
Add comment · Show 4 · 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 UnityDev0008 · May 25, 2011 at 04:45 AM 0
Share

Yes i am using the offical version, and I am trying to use the System.Data.SQLite namespace, which gives the same result...

Asfar as the working in JS but not C# take a look at this post http://forum.unity3d.com/threads/28500-SQLite-Class-Easier-Database-Stuff

Thanks for your time in trying to help me aswell, hopefully we can reach a conclusion.

avatar image yoyo · May 25, 2011 at 06:14 AM 0
Share

Did you put System.Data.Sqlite.dll into your Assets folder?

avatar image Bunny83 · May 25, 2011 at 02:25 PM 1
Share

I can't see any post that it doesn't work in C#. I just see a lot post that complains that it doesn't work with JS. Anyway this thread is not about the official SQLite library. Do you have the dll in your assets like yoyo said? Don't put the dll into the plugins folder. This folder is for native code dlls. Just somewhere in your assets, like a script ;)

avatar image UnityDev0008 · May 26, 2011 at 06:06 AM 0
Share

Hey guys,

No i didnt have the System.Data.Sqlite.dll file in my assets folder >< this did open clear that problem but now when trying to open my database i am getting

dllnotfoundexception sqlite.interop.dll
error...any ideas?

avatar image
0

Answer by cristoph1 · Jul 19, 2011 at 09:45 AM

A really dedicated solution as local data storage for your games is Siaqodb see more info here: http://siaqodb.com/?p=482

  • easy to use, very simple API

  • works on all platforms: PC, Mac, iOS, Android

  • works for all Unity3D editions(not needed Pro edition)

  • no SQL knowledge needed

  • 100% managed code

  • small footprint

Just put a siaqodb.dll in your scripts folder and GO!, no extra configuration, no nightmares with unmanaged references

Comment
Add comment · 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
0

Answer by Oksana Iashchuk · Sep 10, 2012 at 07:14 PM

that is the best solution for you http://u3d.as/content/orange-tree/sqlite-kit/3ka That is 100% managed code, full SQLite3 support, all platforms. No native dependencies.

Comment
Add comment · Show 2 · 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 Bunny83 · Sep 10, 2012 at 09:52 PM 0
Share

In my eyes $100 is a bit expensive for a ported public domain software.

Here's a free 100% managed port of sqlite 3.7.7.1. However it probably doesn't work in the webplayer since you can't access any files on the clients PC.

avatar image Oksana Iashchuk · Sep 11, 2012 at 04:21 AM 0
Share

Yes it's based on free version, but we put a big afford to manage it works on unity (original free sqlite-c-sharp doesn't work) at the first place and second we modify that library to support memory stream to make it possible to run on webplayer platform. So it's good time saving dial for you.

avatar image
0

Answer by GreyKid · Feb 07, 2013 at 05:23 PM

You mention the location, Mono.Data.Sqlite.dll

On iOS you would use sqllite3.dylib or some .dylib

This is a good question not just for SQlite implementation, but on the use of Dynamic Link Libraries in general.

Does anyone have a comprehensive list for all SQlite implementations for Mono.Data.Sqlite on these Unity3D platforms?

  • Unity for Linux Stand alone

  • Unity for Android

  • Unity for iOS (what is the exact .dylib name used by Mono.Data.Sqlite ?)

  • Unity for Mac OS X stand alone

  • Unity for Windows stand alone (looks like Mono.Data.Sqlite.dll is required by any installer)

  • Unity for Flash on Linux, Mac OS X and Windows - does Mono or Unity have a plan for checking for Browser I plementations of HTML5 Web Storage System for WebKit specific or Browsws I General?

Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Best practices for multiple databases 1 Answer

Null reference when accessing database manager singleton 0 Answers

SQLite and Lists in C# 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