Unity3d 使用sqlite数据库
dbAccess.js
import System.Data; // we import our data class
import Mono.Data.SqliteClient; // we import our sqlite client
class dbAccess {
// variables for basic query access
private var connection : String;
private var dbcon : IDbConnection;
private var dbcmd : IDbCommand;
private var reader : IDataReader;
function OpenDB(p : String){
connection = "URI=file:" + p; // we set the connection to our database
dbcon = new SqliteConnection(connection);
dbcon.Open();
}
function BasicQuery(q : String, r : boolean){ // run a baic Sqlite query
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = q; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
if(r){ // if we want to return the reader
return reader; // return the reader
}
}
function CreateTable(name : String, col : Array, colType : Array){ // Create a table, name, column array, column type array
var query : String;
query = "CREATE TABLE " + name + "(" + col[0] + " " + colType[0];
for(var i=1; i<col.length; i++){
query += ", " + col[i] + " " + colType[i];
}
query += ")";
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
}
function InsertIntoSingle(tableName : String, colName : String, value : String){ // single insert
var query : String;
query = "INSERT INTO " + tableName + "(" + colName + ") " + "VALUES (" + value + ")";
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
}
function InsertIntoSpecific
相关文档:
前一阵字做项目(嵌入式linux),由于要保存大量的数据,而且最长要保存30天的时间。本来打算保存到文件中,每次启动应用程序的时候重新解析一遍,可是当数据量很大的时候,就出现效率的问题了。所以最后还是放弃了使用文件的打算,决定使用数据库存取数据。
linux下的数据库也很多,有开源的,也有收费的。对于我们来说,肯 ......
SqLite.net的dll为System.Data.SQLite.dll,这种dll分为32位、64位和适用于compactframework三种,在引用时要注意,选择正确的dll。
将要保存图片的字段类型设为blob。代码如下:
private void savePicture()
{
using (SQLiteConnection cnn = new SQLiteConnection(dbPath))
......
搞定了一个困扰许久的问题,原来sqlite中的主键也是可以设置为自增的:)方法就是声明为 INTEGER PRIMARY KEY 的字段可以自动增加。
网上查到资料说,从 SQLite 的 2.3.4 版本开始,如果将一个表中的一个字段声明为 INTEGER PRIMARY KEY,那么只需向该表的该字段插入一个 NULL 值, ......
sqlite-3.3.6编译安装与交叉编译全过程详细记录
下文介绍的内容都是基于 Linux RedHat 9.0 平台的。
一、PC机编译安装
请阅读在安装包里的 INSTALL 文件。或者使用PEAR installer with "pear install sqlite"。SQLite已经内置了,你不需要安装任何附加的软件(additional software)。
Windows users可以下载SQLite扩展 ......
CnGuiDB.js
var db : dbAccess;
public var mskin : GUISkin;
private var mstring : String;
var inputStr;
function Start(){
inputStr = "1";
}
function search(mid)
{
db = new dbAccess();
db.OpenDB("db1.db");
var tableName = "myTable";
// table name, I want to return everyo ......