Mono.Data.Sqlite 语法

发布于 2024-12-10 12:24:13 字数 1041 浏览 1 评论 0原文

我需要使用 Sqlite,但是我的语法有问题(这就是异常告诉我的...),这是我的代码:

using System;
using System.Data;
using Mono.Data.Sqlite;

class MainClass
{
    public static void Main (string[] args)
    {           
        string connectionString = "URI=file:SqliteTest.db,version=3";

        SqliteConnection conn = new SqliteConnection(connectionString);
        conn.Open();

        SqliteCommand dbcommand = new SqliteCommand(conn);

        string sql_command = "CREATE TABLE transaction (" +
            "id INTEGER PRIMARY KEY," +
            "datetemps TEXT NOT NULL," +
            "description TEXT NOT NULL);";

        Console.WriteLine(sql_command);

        dbcommand.CommandText = sql_command;
        dbcommand.ExecuteNonQuery();

        dbcommand.Dispose();
        conn.Close();
    }
}

这是我收到的异常:

Unhandled Exception: Mono.Data.Sqlite.SqliteException: SQLite error
near "transaction": syntax error

我习惯使用 MySql,它不是我第一次使用数据库,但这是我第一次遇到这种问题,我只是不明白问题是什么,为什么会出现“语法问题”。

感谢您的提示!

I need to use Sqlite, but there's a problem with my syntax (well that's what the Exception is telling me...), Here's my code:

using System;
using System.Data;
using Mono.Data.Sqlite;

class MainClass
{
    public static void Main (string[] args)
    {           
        string connectionString = "URI=file:SqliteTest.db,version=3";

        SqliteConnection conn = new SqliteConnection(connectionString);
        conn.Open();

        SqliteCommand dbcommand = new SqliteCommand(conn);

        string sql_command = "CREATE TABLE transaction (" +
            "id INTEGER PRIMARY KEY," +
            "datetemps TEXT NOT NULL," +
            "description TEXT NOT NULL);";

        Console.WriteLine(sql_command);

        dbcommand.CommandText = sql_command;
        dbcommand.ExecuteNonQuery();

        dbcommand.Dispose();
        conn.Close();
    }
}

Here's the Exception I'm receiving:

Unhandled Exception: Mono.Data.Sqlite.SqliteException: SQLite error
near "transaction": syntax error

I'm used to use MySql and it's not the first time I'm working with DataBases, but it's the first time I got that kind of problem, I just can't figure out what's the problem, why there is a 'syntax problem'.

Thanks for your tips!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与昨日 2024-12-17 12:24:13

Transaction 是 SQLite 中的保留关键字。要将其用作对象名称,请用单引号或双引号、括号或反引号括起来:

CREATE TABLE 'transaction' ...
CREATE TABLE "transaction" ...
CREATE TABLE [transaction] ...
CREATE TABLE `transaction` ...

请注意,括号和反引号不是标准 SQL,因此通常建议使用引号。

有关其他保留字的完整列表:http://www.sqlite.org/lang_keywords.html

Transaction is a reserved keyword in SQLite. To use it as an object name, surround it with single or double quotes, brackets, or backticks:

CREATE TABLE 'transaction' ...
CREATE TABLE "transaction" ...
CREATE TABLE [transaction] ...
CREATE TABLE `transaction` ...

Note that brackets and backticks are not standard SQL, so quotes are generally recommended.

For a complete list of other reserved words: http://www.sqlite.org/lang_keywords.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文