Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎĵµ£º

SQLiteѧϰ±Ê¼Ç

 SQLiteѧϰ±Ê¼Ç
1.²é¿´ÓÐÄÄЩÊý¾Ý¿â,ÏÔʾÊý¾Ý¿âÁбí
show databases;
2.ÏÔʾ±íµÄ½á¹¹
·½·¨Ò»£º
use student;
describe student;
·½·¨¶þ£º
des student.student;
·½·¨Èý£º
show columns from student;
3.ÏÔʾMYSQLµÄ°æ±¾
select version();
4.ÏÔʾ¿âÖеÄÊý¾Ý±í
use  mysql;
show tables;
5.½¨¿â ......

SQLITEÈëÃÅ Öð²½½²½âSQLITEÃüÁîÐÐ(¶þ)

¿ÉÒÔ½Ó×ÅÉÏÒ»²½²Ù×÷£¬Ö±½ÓÏòDOS´°¿ÚÊäÈë.helpÃüÁîÀ´²é¿´SQLiteµÄËùÓÐÃüÁîÐм°½âÊÍÈçÏ£º
F:\>sqlite3
SQLite version 3.6.16
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .help
Ò²¿ÉÒÔctrl+c½áÊøÃüÁÏëDOS´°¿Ú ÊäÈësqlite3Ö´ÐкóÔÙÊäÈë.helpÃüÁîÈçÏ£º
F:\>sqli ......

SQLITEÈëÃÅ Öð²½½²½âSQLITEÃüÁîÐÐ(Èý)

backup ?DB? FILE ±¸·ÝÊý¾Ý¿âµ½Îļþ£¬Ä¬Èϱ¸·ÝµÄÊÇmainÊý¾Ý¿â,Èç¹û²»¸½¼ÓÊý¾Ý¿â£¬test.dbÎļþÖÐĬÈϵÄÖ»ÓÐmainÊý¾Ý¿â¡£ ÃüÁî²Ù×÷¾ÙÀý£º
sqlite> .backup mydb.bak
sqlite>
´Ëʱ¿ÉÒÔÔÙFÅÌ¿´µ½mydb.bakÎļþ£¬ÓüÇʱ¾´ò¿ªËäÈ»ÊÇÂÒÂ룬µ«¿É¿ú¼ûÒ»°ß¡£
.restore ?DB? FILE ´Ó±¸·ÝÎļþ»¹Ô­Êý¾ÝºÍ.backupÏà¶ÔÓ¦. ½ÓÉÏ ......

SQLite³£¼ûÎÊÌâ½â´ð

1¡¢ÈçºÎ½¨Á¢×Ô¶¯Ôö³¤×Ö¶Î?
     ¼ò¶Ì»Ø´ð£ºÉùÃ÷Ϊ INTEGER PRIMARY KEY µÄÁн«»á×Ô¶¯Ôö³¤¡£
     ³¤Ò»µãµÄ´ð°¸£º Èç¹ûÄãÉùÃ÷±íµÄÒ»ÁÐΪ INTEGER PRIMARY KEY£¬ÄÇô£¬ ÿµ±ÄãÔÚ¸ÃÁÐÉϲåÈëÒ»NULLֵʱ£¬ NULL×Ô¶¯±»×ª»»ÎªÒ»¸ö±È¸ÃÁÐÖÐ×î´óÖµ´ó1µÄÒ»¸öÕûÊý£¬Èç¹û±íÊǿյģ¬ ½«»áÊÇ1¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ