I'm trying to add a record to my table using string variables for VarChar columns. I want to insert the values I give it under the next incremented ID. However, I keep getting the SQL error that "no such column exists" when I try and run the code. There is no elaboration on where the error occurs, so I'm sorta stuck. So how can I insert records into a table?
Here's my code
using UnityEngine;
using Mono.Data.Sqlite;
using System.Data;
using UnityEngine.UI;
using System.Collections;
public class AddQuery : MonoBehaviour {
public Text cipher;
public Text initialMessage;
public Text encryptedMessage;
private string _constr = "URI=file:previousMessages.db";
private IDbConnection _dbc;
private IDbCommand _dbcm;
private IDataReader _dbr;
public void AddSQL() {
string _cipher = cipher.text;
string _initialMessage = initialMessage.text;
string _encryptedMessage = encryptedMessage.text;
_dbc = new SqliteConnection(_constr);
_dbc.Open();
_dbcm = _dbc.CreateCommand();
_dbcm.CommandText = "CREATE TABLE IF NOT EXISTS previousMessages (ID INTEGER NOT NULL PRIMARY KEY , Cipher VARCHAR(5000) NOT NULL, InitialMessage VARCHAR(5000) NOT NULL,EncryptedMessage TEXT NOT NULL)";
_dbr = _dbcm.ExecuteReader();
_dbr.Close();
_dbcm.CommandText = "INSERT INTO previousMessages ( Cipher, InitialMessage, EncryptedMessage) VALUES ( "+_cipher+", "+_initialMessage+", "+_encryptedMessage+")";
_dbr = _dbcm.ExecuteReader();
_dbr.Close();
_dbcm.CommandText = "SELECT FROM previousMessages (Cipher, InitialMessage, EncryptedMessage) VALUES ( " + _cipher + ", " + _initialMessage + ", " + _encryptedMessage + ")";
_dbr = _dbcm.ExecuteReader();
while (_dbr.Read())
{
Debug.Log("Cipher: " + _dbr["Cipher"] + "\t Initial: " + _dbr["InitialMessage"]);
}
}
}