Mono.Data.Sqlite syntax
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!
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
精彩评论