简体   繁体   English

统一3D中的SQLite本地数据库

[英]SQLite local database in unity 3D

I am a new programmer for unity 3D v4.5 pro.I am using unity 3D for my augmented reality application and i have chosen SQLite to create and easily handle with my database (after building it on android). 我是unity 3D v4.5 pro的新程序员。我在我的增强现实应用程序中使用unity 3D,我选择了SQLite来创建并轻松处理我的数据库(在Android上构建数据库之后)。 I Found 2 scripts here in java http://wiki.unity3d.com/index.php/SQLite ...I converted it to c#(because i am programming with c#)and it helped me alot but i just couldn't find a method "query" to delete for example only firstName or LastName ..I tried like that : 我在Java http://wiki.unity3d.com/index.php/SQLite中找到了2个脚本...我将其转换为c#(因为我正在使用c#进行编程),它对我有很大帮助,但我却找不到一种方法“查询”删除例如仅firstName或LastName ..我尝试这样:

public void DeleteFrom ( String tableName,String itemToDelete, String wPar,String wValue )
{
    string query ;
    query = "DELETE FROM " + tableName + " WHERE " + itemToDelete + wPar + wValue ;        
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
}

then i call it in the other script "usethe database" as it is bellow 然后我在另一个脚本“使用数据库”中将其称为

public void  DeleteRow(string FirstName )
{
    db.DeleteFrom("'"+TableName+"'","FirstName","=","'"+firstName+"'");
}

But what i get is deleting the whole Row ( firstName lastName) 但是我得到的是删除整个行(firstName lastName)

I don't know if you have understand what i mean: i just want to delete firstName and keep in my datatable it's assignment which is lastName so i can assign for that lastName later any other new firstName. 我不知道您是否理解我的意思:我只想删除firstName并将其保留在我的数据表中,这就是lastName的分配,因此我以后可以为该lastName分配任何其他新的firstName。 I hope you understant my point .Please, i'll appreciate any help and thank you in advance. 希望您能理解我的观点。请给我任何帮助,并在此先感谢您。 :) :)

If I am understanding you correctly, it sounds like you don't want to do an actual delete. 如果我正确理解您的声音,听起来您不想执行实际的删除操作。 There is no such thing as deleting a field, only an entire row. 没有删除字段,只有整行的事情。 Instead what you want is an Update. 相反,您想要的是更新。 Use this code to clear out the first name field of the row: 使用此代码清除该行的名字字段:

public void ClearFirstName(string tableName, string firstname )
{
    string query ;
    query = "UPDATE " + tableName + " SET FirstName = '' WHERE FirstName = '" + firstname + "'";        
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
}

The issue with this code is that once you clear the first name, then you won't be able to reference it a second time (it will be empty). 这段代码的问题在于,一旦您清除了名字,您将无法再次引用它(它将为空)。 I suggest you add a unique numeric ID field to reference each row in your table. 我建议您添加一个唯一的数字ID字段以引用表中的每一行。 Then you can use that ID in the WHERE clause of your SQL statements. 然后,您可以在SQL语句的WHERE子句中使用该ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM