Search Unity

Unity and Sqlite

Discussion in 'Editor & General Support' started by Stick, Dec 19, 2007.

  1. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    Writing a plugin for the ObjC library is a major pain, due to iOS not allowing Marshal.GetFunctionPointerFromDelegate() not working. I tried implementing the standard C sqlite library as a plugin and it was messy and awkward without a proper callback system.
     
  2. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    I am trying to implement flying meat database as a plugin, which is built on objective C. Do you think thatd still be weird and awkward?

    I would prefer to use more Xcode and built in things, rather than another mono component as I'm not as trusting of the mono components and I assume an objective C implementation will be better on performance. But are those assumptions wrong?
     
  3. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    Can you explain some more about what the purpose is for that link.xml file?
     
  4. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    That part is for using ByteCode Stripping. Link.xml lists all classes that are not allowed to be stripped, even if they are not referenced. Mono.Data.SQLite.dll references Globalization from native code, and this tricks the byte code stripper into thinking it's not used and removing it from the build causing SQLite to work in editor but fail after stripping.

    In short, that file is telling the bytecode stripper not to strip System.Globalization.CultureInfo from mscorlib.dll, even if it can't figure out who is referencing it.

    As far as the flying meat database, I've got no idea what that is. You can go with an ObjC implementation but a lack of functional C++ to C# callbacks, as well as a need to run many types through the marshaller before being able to properly read them in C# means it could end up potentially quite clunky. You may have much better success than I did, but my attempts at making a C SQLite plugin and using that turned out much, much worse than the C# SQLite plugin (though even that uses C calls under the hood for the actual database work). If you are comfortable in ObjC and can handle most of the processing from within the plugin you could do much better, I just couldn't find a good design that didn't involve some messy hacks to get all the required data back into C#.

    Edit: As a correction, there are functional callbacks, but they are not clean, and rely on linking your plugin to lib-iphone.a when running on device, and lib-unity.a when running on mac. Then you can use the C side Mono functions, callback samples are available at their embedding how-to:
    www.mono-project.com/Embedding_Mono

    You could end up with some very messy function calls within your plugin if you rely solely on that, but it is possible. These don't screw up AOT compiler like FunctionPointerToDelegate does.
     
    Last edited: Oct 21, 2011
  5. bioduds

    bioduds

    Joined:
    Nov 19, 2011
    Posts:
    16
  6. Oksana-Iashchuk

    Oksana-Iashchuk

    Joined:
    Sep 10, 2012
    Posts:
    126
  7. Welias D.

    Welias D.

    Joined:
    Jun 12, 2013
    Posts:
    36
    Dreamora, Thank You! Just wanted you to know that your dropbox sqlite implementation still works! Actually if you load it into Unity 4 and let it upgrade it, there is no need to update the perl scripts in the core any longer. After implementing Streaming to files, then the Javascript mono wrapper for SQLite and a failed C# attempt at wrapping SQLite myself, your example above sent me on the right path! Thanks!
     
    Last edited: Jun 16, 2013
  8. gdbjohnson

    gdbjohnson

    Joined:
    Dec 16, 2014
    Posts:
    40
    I ended up referencing the Mono.Data.Sqlite dll for my project, and used it directly. Didn't realize that Unity will get mad at you when you try to deploy it to your device (iOS for me, not sure what happens with Android) if you don't have a Pro licence. The DLL references the Net.Sockets namespace, which is a reserved namespace in Unity for the Pro license with the following error:

    "Error building Player: SystemException: System.Net.Sockets are supported only on Unity iOS Pro. Referenced from assembly 'Mono.Data.Tds'."

    Wanted to write this as a heads up to future readers. I'm on Unity 4.6.

    Looks like there are other solutions out there. Going to check out Dreamora's solution. Also found this one:

    https://github.com/Busta117/SQLiteUnityKit/
     
    Last edited: Feb 20, 2015
  9. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    221

    I have created a plugin for SQLite database, it may help you. If you have any suggestion to improve this plugin then you are most welcome to suggest me.
    http://u3d.as/content/devesh-pandey/sqlite-database
     
  10. rafaelzuckerberg

    rafaelzuckerberg

    Joined:
    Aug 13, 2015
    Posts:
    3
    Guys, I see many forums and tutors, but without success yet on Sqlite X andoird, connect, but even run, can"t see data in android, how to solve ?