Нужна помощь в отслеживании SQLiteException: нераспознанный токен - PullRequest
0 голосов
/ 28 мая 2018

Я новичок в работе с 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()

1 Ответ

0 голосов
/ 28 мая 2018

Я почти уверен, что "нераспознанный токен" - это имя таблицы и что оно не является соответствующим образом заключенным, что необходимопотому что имя таблицы начинается с цифры.

Решение может заключаться в том, чтобы заключить ее в [] , `` (серьезные акценты, т. е. ключ кслева от клавиши 1), '' или поочередно начинайте числовую часть с нечислового допустимого символа.

Подробнее о включении идентификаторов в SQL как понятно SQLite - ключевые слова SQLite

Вот пример с 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
  • Эта последняя попытка также повторяет ошибку;бар фактическое целенаправленно измененное имя таблицы.
...