|
FAQ
Jan 8, 2021 14:21:44 GMT
Post by echo17 on Jan 8, 2021 14:21:44 GMT
Q: How do I create a table by type or name?
You could use reflection, like:
public SimpleSQLManager dbManager;
public void CreateTableByType(System.Type tableType) { var method = this.GetType().GetMethod("CreateTable"); var generic = method.MakeGenericMethod(tableType); generic.Invoke(dbManager, null); }
public void CreateTableByName(string tableName) { var tableType = System.Type.GetType(tableName); CreateTableByType(tableType); }
If you'd like the above code to be inside the SimpleSQLManager, you could create an extension class and reference that in your project instead of the base class. Something like:
using System;
namespace SimpleSQL { public class SimpleSQLManager_Extended : SimpleSQLManager { public void CreateTableByType(System.Type tableType) { var method = this.GetType().GetMethod("CreateTable"); var generic = method.MakeGenericMethod(tableType); generic.Invoke(this, null); }
public void CreateTableByName(string tableName) { var tableType = System.Type.GetType(tableName); CreateTableByType(tableType); } } }
Then, you can just reference the methods directly from your manager, like:
dbManager.CreateTableByName("SimpleSQL.Demos.StarShip"); dbManager.CreateTableByType(typeof(StarShip));
Alternatively, you can use straight sql syntax, like:
var sql = "CREATE TABLE MyTable (\"FieldA\" INTEGER PRIMARY KEY NOT NULL, \"FieldB\" TEXT, \"FieldC\" FLOAT DEFAULT 100)"; dbManager.Execute(sql);
|
|
|
FAQ
Feb 3, 2021 12:44:23 GMT
Post by echo17 on Feb 3, 2021 12:44:23 GMT
Q: In Android, I get the error "Attribute application@allowBackup value=(false) from [:unityLibrary] AndroidManifest.xml". How do I fix?In Publish Settings select 'Custom Main Manifest': This creates an AndroidManifest.xml file in Assets folder. Then change: <application>
to: <application tools:replace="android:allowBackup">
|
|
|
FAQ
Dec 27, 2021 15:03:08 GMT
Post by echo17 on Dec 27, 2021 15:03:08 GMT
Q: How do I fix the error: "Unable to find class org/sqlite/database/sqlite/SQLiteCustomFunction"?
If you have minify enabled in the Android build settings, you will need to add a proguard user file with the lines:
-keep class org.sqlite.** { *; }
-keepclasseswithmembernames class * { native <methods>; }
|
|
|
FAQ
Jan 2, 2022 15:40:57 GMT
Post by echo17 on Jan 2, 2022 15:40:57 GMT
Q: How do I fix a DllNotFoundException: sqlite3 on Windows?Be sure you are not trying to call any function on the SimpleSQLManager component in any of your Awake methods. Generally speaking, the Awake method is reserved for internal initialization of a component. For intra-component communication, you should use the Start method of your components, which is called after the Awake method of every component. This ensures all components have initialized internally. In the case of the SimpleSQLManager, this means the library is initialized and the sqlite dll is copied into your device's executable path. If you absolutely must call a SimpleSQL function in an Awake method of a component, then you will need to ensure that the SimpleSQLManager script execution order has a higher priority, meaning that its Awake method is called earlier than other components. Take a look at this search for more information: Google SearchNote: this only happens on Windows devices because Windows does not include the sqlite dll by default. MacOS, iOS, and Android all have their versions of sqlite in place, so Windows needs to have the library copied in the SimpleSQLManager component's Awake method. Also, go to your build folder, inside the data folder, check the Plugins\x86 folder and make sure there are no sqlite dlls there. Sometimes Unity will package and extra sqlite dll in this location when it should not. I haven't discovered the cause of this, and I cannot duplicate the issue, so deleting the file manually is the only course of action, currently. The only sqlite3.dll file should be in your root build folder, and only after the first time you run your application. SimpleSQL copies the sqlite3.dll to your root folder in its Awake method the first time you run your app.
|
|
|
FAQ
Feb 20, 2022 13:06:44 GMT
Post by echo17 on Feb 20, 2022 13:06:44 GMT
Q: How do I store Vectors in my database?There are a couple of ways you could handle vectors. One would be to create three fields for each vector3, one for each of the vector3's components. I personally wouldn't do this since it would require a lot of post processing and extra fields. A much better way would be to create a TEXT field to store the vector3 as a string. You would need to extract the Vector3 when reading and serialize when writing. You could wrap this up in the property of the ORM itself. Something like:
using UnityEngine; using SimpleSQL; using System;
public class MyVectorTable { public int ID { get; set; }
private Vector3 _myVector3; private string _myVector3Serialized;
[Ignore] public Vector3 MyVector3 { get { return _myVector3; } set { MyVector3Serialized = value.ToString(); } }
public string MyVector3Serialized { get { return _myVector3Serialized; } set { _myVector3Serialized = value; var components = _myVector3Serialized.Replace("(", "").Replace(")", "").Split(","[0]); _myVector3 = new Vector3((float)Convert.ToDouble(components[0]), (float)Convert.ToDouble(components[1]), (float)Convert.ToDouble(components[2])); } } }
Note that you can use the Ignore attribute so that SimpleSQL will not try to read or write a particular property. The MyVector3 property is only used by you in the code, but is not stored in the database. The MyVector3Serialized property is the one that is stored, but not used in code. You would set up the table in the database like: That way you are storing the serialized vector3 as a string in your table, but in code, you only need to reference the actual vector. Using the code would be something like:
var newRecord = new MyVectorTable(); newRecord.ID = 1; newRecord.MyVector3 = new Vector3(1.1f, 2.2f, 3.3f);
dbManager.Insert(newRecord);
var records = dbManager.Query<MyVectorTable>("SELECT * FROM MyVectorTable");
foreach (var record in records) { Debug.Log(record.ID + ": " + record.MyVector3); }
|
|
|
FAQ
Apr 29, 2022 13:14:01 GMT
Post by echo17 on Apr 29, 2022 13:14:01 GMT
Q: How do I fix errors like "doesn't have column X" or "get method not found"?Be sure your ManagedStrippingLevel in the Unity Player settings is set to Low or Disabled. When Unity strips at a higher level, some .NET functionality is removed, including crucial reflection methods that are needed for the ORM mapping.
|
|
|
FAQ
Oct 12, 2022 13:02:19 GMT
Post by echo17 on Oct 12, 2022 13:02:19 GMT
Q: How do I load a database at runtime from a path outside of the persistent data path?In your inspector for SimpleSQLManager, be sure you have "Override Base Path" blank, "Change Working Name" to false, and "Overwrite if Exists" to false. In your code, you can use something like this: dbManager.changeWorkingName = true; dbManager.workingName = "test.sqlite"; dbManager.overrideBasePath = "C:\Some\Path\To\The\File"; dbManager.Initialize(true);
Note: for some mobile devices, you will not be able to load outside of the persistent data path for security reasons.
|
|
|
FAQ
Mar 15, 2023 10:19:16 GMT
Post by echo17 on Mar 15, 2023 10:19:16 GMT
Q: Can parameters be used for sql injection attacks?Yes, if your query is running based on user input, parameters can be used for sql injection attacks. Parameters should only be used in queries that do not utilize user input. In the cases where users are inputting data, you should build your sql strings explicitly. Please see this link for more information: link
|
|
|
FAQ
Sept 14, 2023 9:39:35 GMT
Post by echo17 on Sept 14, 2023 9:39:35 GMT
Q: How do I use a different version of the sqlite library?You can download other versions of the sqlite library from sqlite.org. You will need to open up the source code for SimpleSQL and replace the libraries found at the path SimpleSQL_Runtime/Resources, SimpleSQL_Runtime_Lite/Resources, and SimpleSQL_Runtime_x64/Resources. You will need to rename the new files to match those found in the resources folder, including changing the extension to ".resource". You can then compile the project and copy the Editor DLLs to your project. Be sure to go to the Unity menu Tools > SimpleSQL > Options and choose a different platform, wait a few seconds, then switch to a new platform. That will load the newly compiled runtime library that is embedded in the editor dll. Please see this FAQ for more information on compiling the SimpleSQL library: linkNote: using any sqlite library other than the one included with SimpleSQL has no guarantee of working. Please use at your own risk.
|
|