|
Post by lotusdesignz on Mar 15, 2021 11:00:33 GMT
first of all, i'm sort of a beginner with unity and programming in general. so if i say anything stupid, please forgive me.
i followed the documentation in regards to creating the database file and the DB Manager. i opened the database file in DB Browser and created the table and column. then i made a simple project to test SimpleSQL out with the following script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using SimpleSQL; public class SQLScript : MonoBehaviour { public SimpleSQLManager dbManager; public InputField inputText; public void SaveData() { string sqlString = "INSERT INTO MyFirstTable (FIRST_COLUMN) VALUES (?)"; dbManager.Execute(sqlString, inputText.text); } }
this is what shows in the Debug Trace:
Executing: INSERT INTO MyFirstTable (FIRST_COLUMN) VALUES (?) 0: testing insert UnityEngine.Debug:Log (object) SimpleSQL.SQLiteCommand:ExecuteNonQuery (SimpleSQL.SQLite3/Result&,string&) SimpleSQL.SQLiteConnection:Execute (string,object[]) SimpleSQL.SimpleSQLManager:Execute (string,object[]) SQLScript:SaveData () (at Assets/SQLScript.cs:15) UnityEngine.EventSystems.EventSystem:Update () (at C:/Program Files/Unity/Hub/Editor/2020.3.0f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:385)
i opened the database file in DB Browser and checked the table, but the data i inserted isn't showing. what am i doing wrong?
|
|
|
Post by echo17 on Mar 15, 2021 12:27:24 GMT
|
|
|
Post by lotusdesignz on Mar 15, 2021 13:02:44 GMT
Hi, thanks for the reply. I included a Select method in my project, but it's still not showing the data.
public void LoadData() { string sqlString = "SELECT * FROM MyFirstTable"; var result = dbManager.Execute(sqlString);
displayText.text = result.ToString(); }
I'm using Unity 2020.3.0f1 if that makes any difference.
|
|
|
Post by lotusdesignz on Mar 15, 2021 13:55:20 GMT
Nevermind, I figured it out. I was looking at it the completely wrong way, you can already see it in the syntax. Anyways thanks.
|
|
|
Post by echo17 on Mar 15, 2021 14:16:31 GMT
Ah, I see. Yes, inserting, deleting, and updating require Execute, while retrieving data requires Query. Just following up so that others can see what the fix would be in this situation.
|
|
|
Post by lotusdesignz on Mar 15, 2021 15:38:03 GMT
Yes, and not only that, you really need a set/get class to make Select queries. I'm kind of surprised a set/get class is not pointed out as a basic requirement, somehow, maybe in the SimpleSQL inspector property or somewhere. Or I guess you guys are really advanced at this, it's like second nature. It just really threw me off, it seems like critical information especially for a newbie like me.
|
|
|
Post by echo17 on Mar 15, 2021 18:01:37 GMT
Check out section 6.2 in the SimpleSQL UserManual documentation (located at SimpleSQL/Documentation/SimpleSQL UserManual.pdf). This describes how to set up your ORM for data retrieval. Chapter 7 deals with queries that use these ORM classes to store and update. Also check out all the demos that come with the plugin. They all use the ORM classes and should help guide you in setting up your own. Finally, there is a quick start tutorial located here: YouTube: SimpleSQL Quick Start Tutorial that covers the basics of setting up queries. This tutorial is linked on the asset store page if you ever need to reference it again.
|
|