|
Post by nicolorem on Jun 30, 2021 18:48:07 GMT
Hello there,
I have a question, probably a silly one but... Here is my code:
public void SearchAWord () { ImportedSqlSearch = GameObject.Find("SearchButton").GetComponent<Searching>().SqlSearch; ImportedSearchValue = GameObject.Find("SearchButton").GetComponent<Searching>().SearchValue;
_data = new List<ScrollerData>(); List<Word> wordList = dbManager.Query<Word>(ImportedSqlSearch, ImportedSearchValue); foreach (Word wordRecord in wordList) { _data.Add(new ScrollerData() { QuestionValue = wordRecord.english, AnswerValue = wordRecord.spanish}); } myScroller.Delegate = this; myScroller.ReloadData(); }
ImportedSqlSearch = SqlSearch = "SELECT * FROM words WHERE english = ?"; ImportedSearchValue = SearchValue = a word the user is looking for and type in an input.
Here is my issue: How do I pass SearchValue to the query? With my code, it's not working when I put a variable name. But it is working when I hardcode a word.
Can you help me please?
Thanks,
Nicole
|
|
|
Post by echo17 on Jul 1, 2021 13:15:55 GMT
Can you elaborate when you say it isn't working? Does this mean you are getting an error, or unexpected results? Your code seems fine, but I don't have any way to test it. The first thing I would check is that you are getting the values from the buttons and those values are what you expect. Here is a sample scene that shows passing parameters successfully: ParameterPass.unitypackage (8.78 KB) Just import into a project that contains SimpleSQL already installed. Relevant code included in the sample: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ParameterPass : MonoBehaviour { private SimpleSQL.SimpleSQLManager dbManager;
// Start is called before the first frame update void Start() { dbManager = GetComponent<SimpleSQL.SimpleSQLManager>(); Search("SELECT * FROM Weapon WHERE WeaponName = ?", "Sword"); }
private void Search(string sql, string parameter) { var weaponList = dbManager.Query<SimpleSQL.Demos.Weapon>(sql, parameter);
foreach (var weapon in weaponList) { Debug.Log(weapon.WeaponID + " : " + weapon.WeaponName); } } }
|
|
|
Post by nicolorem on Jul 2, 2021 12:29:46 GMT
Hello echo17! Thank you for your answer. Indeed, everything was ok code-wise. The issue came from TextMeshPro, which I used for my text input field. For some mysterious reason, it generates an issue and the text field string is not handled properly. I replaced the TMP text field with a "classic" one and the problem is gone!
|
|
|
Post by echo17 on Jul 2, 2021 12:31:03 GMT
Excellent! I'm glad you found the solution, thanks for letting us know.
|
|