我在与SQLite合作时崭露头角我今天大部分时间都在努力解决这个问题,而且我在追踪错误的方面遇到了麻烦。错误是在dbManager.Execute(sql, driftID, driftName, GenerateDriftStep(), driftLat, driftLong, driftTexLocation);
行引起的,但我不确定为什么。我仔细检查以确保表名是正确的,它是。任何人都可以看到无法识别的令牌隐藏在哪里?谢谢!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using SimpleSQL;
using System;
public class CreateNewDrift : MonoBehaviour
{
// reference to the database manager in the scene
public SimpleSQLManager dbManager;
// reference to the output text in the scene
public Text outputText;
// Drift Variables
public int driftNumSteps;
private string driftID;
private string driftName = "temp";
private float driftLat = 0.0f;
private float driftLong = 0.0f;
private string driftTexLocation = "temp";
string GenerateDriftID()
{
driftID = Guid.NewGuid().ToString().Replace("-", "");
return null;
}
string GenerateDriftStep()
{
string driftStepInput = GetComponent<DriftInstruction>().ConstructStep();
return driftStepInput;
}
public void CreateTable()
{
GenerateDriftID();
string sql =
"CREATE TABLE " + "\"" + driftID + "\"" + " " +
"(\"DriftIndex\" INTEGER PRIMARY KEY AUTOINCREMENT, " +
"\"DriftID\" VARCHAR(60), " +
"\"DriftName\" VARCHAR(60), " +
"\"DriftStep\" TEXT, " +
"\"DriftLat\" FLOAT, " +
"\"DriftLong\" FLOAT, " +
"\"DriftTexLocation\" VARCHAR(255))";
dbManager.Execute(sql);
PopulateTable();
}
public void PopulateTable()
{
string sql =
"INSERT INTO " + driftID + " " +
"(DriftID, DriftName, DriftStep, DriftLat, DriftLong, DriftTexLocation) " +
"VALUES(?, ?, ?, ?, ?, ?)";
dbManager.BeginTransaction();
while (driftNumSteps > 0)
{
dbManager.Execute(sql, driftID, driftName, GenerateDriftStep(), driftLat, driftLong, driftTexLocation);
driftNumSteps--;
}
dbManager.Commit();
}
}
完整错误:
SQLiteException: unrecognized token: "8d51c6b280c64bea848f29e5cad91ee3"
SimpleSQL.SQLite3.Prepare2 (IntPtr db, System.String query)
SimpleSQL.SQLiteCommand.Prepare ()
SimpleSQL.SQLiteCommand.ExecuteNonQuery ()
SimpleSQL.SQLiteConnection.Execute (System.String query, System.Object[] args)
SimpleSQL.SimpleSQLManager.Execute (System.String query, System.Object[] args)
CreateNewDrift.PopulateTable () (at Assets/_Scripts/CreateNewDrift.cs:65)
CreateNewDrift.CreateTable () (at Assets/_Scripts/CreateNewDrift.cs:51)
UnityEngine.Events.InvokableCall.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:165)
UnityEngine.Events.UnityEvent.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
答案 0 :(得分:2)
我很确定 “无法识别的令牌” 是表格名称,并且它没有被适当地封闭,它会需要是,因为表名以数字开头。
解决方案可以将其包含在 [] ,``(严重重音,即1键左侧的键)中,或者交替使用在数字部分前面加上非数字有效字符。
有关在SQL As Understood By SQLite - SQLite Keywords
处附上标识符的详情这是一个包含4种类型的机箱的示例,最后是一个以数字开头的非封闭/裸表名称: -
CREATE TABLE "2d51c6b280c64bea848f29e5cad91ee3" (col1 TEXT)
> OK
> Time: 0.21s
CREATE TABLE '3d51c6b280c64bea848f29e5cad91ee3' (col1 TEXT)
> OK
> Time: 0.221s
CREATE TABLE [4d51c6b280c64bea848f29e5cad91ee3] (col1 TEXT)
> OK
> Time: 0.206s
CREATE TABLE `5d51c6b280c64bea848f29e5cad91ee3` (col1 TEXT)
> OK
> Time: 0.251s
CREATE TABLE 1d51c6b280c64bea848f29e5cad91ee3 (col1 TEXT)
> unrecognized token: "1d51c6b280c64bea848f29e5cad91ee3"
> Time: 0s