Hey guys, I am trying to get my iOS project ported over to windows phone/store. I am using a Sqlite plugin for iOS and Android, this it here: https://github.com/Busta117/SQLiteUnityKit/ With some minor modifications to get file system I/O I was able to get the plugin working. It is reading from the database, but seems unable to write to it. Also I am consistently getting "stack unstable" errors when running through VS. Do you guys think this plugin is causing more problems for me on this platform than it is solving? should I look into a different solution? Thanks so much in advance for your help!
Hi, stack unstable error usually means that calling convention or parameters of P/Invoke signature and real native function do not match. What DLL are you P/Invoking?
Ah that makes a lot of sense. Unfortunately, I don't really know what I am trying to access on the windows side at the moment. I will be honest that I am just starting the porting process and am trying to cut through the fog to see what the differences are between the different platforms. I did install a sqlite dll through nuget in the VS project. On the Unity side, I am using the project that I linked above. It is using a class called SqliteDatabase.cs and below is the initial callouts to the imported dll: [DllImport("sqlite3", EntryPoint = "sqlite3_open")] private static extern int sqlite3_open (string filename, out IntPtr db); [DllImport("sqlite3", EntryPoint = "sqlite3_close")] private static extern int sqlite3_close (IntPtr db); [DllImport("sqlite3", EntryPoint = "sqlite3_prepare_v2")] private static extern int sqlite3_prepare_v2 (IntPtr db, string zSql, int nByte, out IntPtr ppStmpt, IntPtr pzTail); [DllImport("sqlite3", EntryPoint = "sqlite3_step")] private static extern int sqlite3_step (IntPtr stmHandle); [DllImport("sqlite3", EntryPoint = "sqlite3_finalize")] private static extern int sqlite3_finalize (IntPtr stmHandle); [DllImport("sqlite3", EntryPoint = "sqlite3_errmsg")] private static extern IntPtr sqlite3_errmsg (IntPtr db); [DllImport("sqlite3", EntryPoint = "sqlite3_column_count")] private static extern int sqlite3_column_count (IntPtr stmHandle); [DllImport("sqlite3", EntryPoint = "sqlite3_column_name")] private static extern IntPtr sqlite3_column_name (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_type")] private static extern int sqlite3_column_type (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_int")] private static extern int sqlite3_column_int (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_text")] private static extern IntPtr sqlite3_column_text (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_double")] private static extern double sqlite3_column_double (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_blob")] private static extern IntPtr sqlite3_column_blob (IntPtr stmHandle, int iCol); [DllImport("sqlite3", EntryPoint = "sqlite3_column_bytes")] private static extern int sqlite3_column_bytes (IntPtr stmHandle, int iCol); private IntPtr _connection; private bool IsConnectionOpen { get; set; } private string pathDB; I am assume that I am going to have to write another Unity class to wrap the windows specific dll for sqlite? any thoughts?
Where did you get sqlite dll? It might be it was built without using stdcall convention. You should be able to check that by looking into sqlite headers.
that sqlite3 dll i believe comes straight from the sqlite homepage downloads section. I am not completely sure as it was packaged with the plugin I have been using. I am thinking of following the instructions in this post: http://blogs.msdn.com/b/robertgreen/archive/2012/11/13/using-sqlite-in-windows-store-apps.aspx to get sqlite basically running and then try to retro fit the calls to that particular dll within the same class just wrapped in preprocessor directives for windows_metro/wp8
Just poking around on the Sqlite home page in the downloads sections, do you think these would help? Precompiled Binaries for Windows Phone 8 sqlite-wp80-winrt-3080301.vsix (2.90 MiB) A complete VSIX package with an extension SDK and all other components needed to use SQLite for application development with Visual Studio 2012 targeting Windows Phone 8.0. (sha1: 4ce17b36a740a529ebfe7dc3f2876b7787278403) Precompiled Binaries for Windows Runtime sqlite-winrt-3080301.vsix (4.38 MiB) A complete VSIX package with an extension SDK and all other components needed to use SQLite for WinRT application development with Visual Studio 2012. (sha1: df775f296e71d1a0bace50c0e97920f8a491e316) sqlite-winrt81-3080301.vsix (4.36 MiB) A complete VSIX package with an extension SDK and all other components needed to use SQLite for WinRT 8.1 application development with Visual Studio 2013. (sha1: ffb528d3a3d810c577a7f561bf79e58461b5dfd3)
They should work, however, I can't be sure that the P/Invoke signatures you have are correct. Furthermore, you cannot use P/Invoke on Windows Phone, as Microsoft does not support it. On the other hand, with the DLLs you downloaded, you got .winmd files as well? Those allow to access native C++ code without the help of P/Invoke. That works only on Windows Store Apps and Windows Phone, though.
Thanks for your help Tautvydas, I think I have narrowed down what the issue is. Unfortunately I think it has highlighted a bigger issue, that is that sqlite in Unity is a pretty unstable persistent storage solution. Having to have multiple binaries available for each platform, in specific places with more specific code for each is just a problem for me. I think I am going to rip through and remove all references to sqlite and replace them with some sort of data serialization. Thank you for your help though!
n8, sir I am also trying to port our game into WP8 and this sqlite thing is really giving us a hard time. Can you give us some instructions on how to do it? Your help would be greatly appreciated.
Hey Corpsegrinder, see my reply to your private message. For everyone else who stumbles across this thread, basically I gave up on sqlite as it just seems far to unstable and basically unsupported to be used effectively on a cross platform game. My solution was to ditch sqlite all together and instead create Model classes to store all of my data in game. I then store these models of data in List<ModelClass> collections. From there I can use basic C# linq queries to look up the information that I may need at anytime with "sql like" syntax. This solution has worked really well for my scenario and has even opened up possibilities that would have been tremendously difficult to accomplish with sqlite. I hope this helps. Please let me know if there is anything more I can share on the subject.
Hi n8, i am having troubles converting Android app to WP8, and getting this error: NotSupportedException: DllImport cannot be used on user-defined methods. at SqliteDatabase.sqlite3_open(String filename, IntPtr& db) at SqliteDatabase.Open(String path) at SqliteDatabase.Open() at SqliteDatabase.ExecuteQuery(String query) at DataAccessLayer.GetPlayerStats() at DataAccessLayer.OpenDatabase(String dbName) at MainMenuCtrl.Awake() at MainMenuCtrl.$Invoke2(Int64 instance, Int64* args) at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) (Filename: TODO Line: 0) What could cause this? I think it is something in sqlite.dll right?
Ok, can anyone help me. I have android app that has sqlite3 and i am trying to build the same project to WinPhone8. When i do it.. And run it in Windows Phone emulator.. I get this message. Really trying but can't figure it out what am i doing wrong. n8, can help me and tell me how did you manage to transfer database you had for Android to Win Phone 8 ?