【发布时间】:2017-04-27 16:31:14
【问题描述】:
我正在尝试使用 SQLite 与 Unity3D 的集成,就像在某些教程中一样。 但是我遇到了问题..
这是我的创建表:
public void CreateTablePaciente ()
{
string sqlCreatePacientes;
DbConnection connection = new SqliteConnection(urlDataBase);
IDbCommand command = connection.CreateCommand();
connection.Open();
sqlCreatePacientes = "CREATE TABLE IF NOT EXISTS " + tabela
+ " (cpf TEXT PRIMARY KEY, "
+ "nome TEXT NOT NULL, "
+ "sexo TEXT NOT NULL, "
+ "endereco TEXT NOT NULL, "
+ "email TEXT, "
+ "dataNascimento TEXT NOT NULL, "
+ "telefone TEXT NOT NULL, "
+ "numeroConsultas TEXT NOT NULL"
+ ");";
command.CommandText = sqlCreatePacientes;
command.ExecuteNonQuery ();
}
这是我的插入方法:
public void InsertPaciente (Paciente paciente)
{
string sqlInsert;
DbConnection connection = new SqliteConnection(urlDataBase);
IDbCommand command = connection.CreateCommand();
sqlInsert = "INSERT INTO " + tabela
+ " (cpf, nome, sexo, endereco, email, dataNascimento, telefone, numeroConsultas)"
+ " VALUES ("
+ paciente.Cpf + ", "
+ paciente.Nome + ", "
+ paciente.Sexo + ", "
+ paciente.Endereco + ", "
+ paciente.Email + ", "
+ paciente.DataNascimento + ", "
+ paciente.Telefone + ", "
+ paciente.NumeroConsultas
+ ");";
connection.Open();
command.CommandText = sqlInsert;
Debug.Log (sqlInsert);
command.ExecuteNonQuery();
}
插入查询:
INSERT INTO paciente (cpf, nome, sexo, endereco, email, dataNascimento, telefone, numeroConsultas) 值 (00000000000, Nome 0, m, rua aposkpaosk0, aosais@asiapos.xpco0, 0/00/00, 00000000000, 0 );
但是我遇到了这个 SQLite 错误..
SqliteSyntaxException:接近“0”:语法错误
Mono.Data.SqliteClient.SqliteCommand.GetNextStatement (IntPtr pzStart, System.IntPtr& pzTail, System.IntPtr& pStmt)
Mono.Data.SqliteClient.SqliteCommand.ExecuteReader(CommandBehavior 行为、布尔值 want_results、System.Int32& rows_affected)
Mono.Data.SqliteClient.SqliteCommand.ExecuteNonQuery()
PacienteDAO.InsertPaciente (.Paciente paciente)(位于 Assets/C#Script/PacienteDAO.cs:73)
create table 似乎没问题,但我不知道“near: '0'”是什么意思。我该如何解决?
【问题讨论】:
-
不要写SQL执行使用字符串连接,使用参数。