I'm somewhat new to C#, and completely new to SQLite. SQLite is probably way overkill for this project but I wanted to learn it so I'm using it anyway. I'm making a discord bot. The problem is that whenever I do my only command it terminates. I've managed to find the source of the problem and its a command in SQLite to insert data into a row.
m_dbConnection.Open();
string sql = $"INSERT INTO `Cases` ( plaintiffid, accusedid, channelid ) values ( {plaintiff.Id.ToString()}, {accused.Id.ToString()}, {caseChannel.Id.ToString()} )";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
m_dbConnection.Close();
Everytime I start the program it also runs this:
public static SQLiteConnection m_dbConnection { get; private set; }
public static string CasePath { get; } = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"/DiscourtBot/Cases.sqlite";
public static void Start()
{
if (!File.Exists("Cases.sqlite"))
{
SQLiteConnection.CreateFile("Cases.sqlite");
m_dbConnection = new SQLiteConnection("Data Source=Cases.sqlite;Version=3;");
m_dbConnection.Open();
string sql = "CREATE TABLE `Cases` ( plaintiffid INTEGER, accusedid INTEGER, channelid INTEGER UNIQUE )";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
m_dbConnection.Close();
}
else m_dbConnection = new SQLiteConnection("Data Source=Cases.sqlite;Version=3;");
}
No exceptions are thrown.
I've tested a bit of the code in another program and this code also causes it to terminate.
SQLiteConnection.CreateFile("Cases.sqlite");
m_dbConnection = new SQLiteConnection("Data Source=Cases.sqlite;Version=3;");
m_dbConnection.Open();
string sql = "CREATE TABLE `Cases` ( plaintiffid BIGINT, accusedid BIGINT, channelid BIGINT )";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
m_dbConnection.Close();
m_dbConnection.Open();
string sqll = $"INSERT INTO `Cases` ( plaintiffid, accusedid, channelid ) values ( 5, 5, 5 )";
SQLiteCommand commandd = new SQLiteCommand(sqll, m_dbConnection);
commandd.ExecuteNonQuery();
m_dbConnection.Close();
Discord ID's usually look something like this: 394343217715216384 I'd appreciate it if anyone could help me.
foo.bar.Id.ToString()