コード例 #1
0
    public void Update_atk_cri_spd(int a_atk, float a_cri, float a_spd, int a_idx)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            string      strsql = string.Format(_queryUpdate_atk_cri_spd, a_idx); //
            qr = new SQLiteQuery(_db, strsql);
            qr.Bind(a_atk);
            qr.Bind(a_cri);
            qr.Bind(a_spd);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #2
0
    //
    //   INSERT CALLBACKS
    //
    //

    void InsertBind(SQLiteQuery qr, object state)
    {
        //
        // insert string and blob
        //
        qr.Bind(testString);
        qr.Bind(testBlob);
    }
コード例 #3
0
    public void OnClickBtnQuit()
    {
        if (GameDirector.inBossZone == false)
        {
            //레벨,최대HP,최대MP,최대EXP,HP,MP,EXP,X,Y,Z,STR,CON,AGI순서
            string      query = "UPDATE Player SET LEVEL=?,MAX_HP=?,MAX_MP=?,MAX_EXP=?,HP=?,MP=?,EXP=?,X=?,Y=?,Z=?,STR=?,CON=?,AGI=?,POINT=? WHERE NAME=?;";
            SQLiteQuery qr    = new SQLiteQuery(db, query);
            qr.Bind(player.Level);
            qr.Bind(player.MaxHp);
            qr.Bind(player.MaxMp);
            qr.Bind(player.MaxExp);
            qr.Bind(player.Hp);
            qr.Bind(player.Mp);
            qr.Bind(player.Exp);
            qr.Bind(player.X);
            qr.Bind(player.Y);
            qr.Bind(player.Z);
            qr.Bind(player.Str);
            qr.Bind(player.Con);
            qr.Bind(player.Agi);
            qr.Bind(player.Point);
            qr.Bind(player.name.GetComponent <TextMesh>().text);
            qr.Step();
            qr.Release();
            if (Inventory.items.Count > 0)
            {
                query = "UPDATE Inventory Set TYPE=?,EA=? WHERE SLOT=?;";
                qr    = new SQLiteQuery(db, query);
                qr.Bind(Inventory.items[0].Type);
                qr.Bind(Inventory.items[0].Ea);
                qr.Bind("SLOT1");
                qr.Step();
                qr.Release();
            }
            if (Inventory.items.Count > 1)
            {
                query = "UPDATE Inventory Set TYPE=?,EA=? WHERE SLOT=?;";
                qr    = new SQLiteQuery(db, query);
                qr.Bind(Inventory.items[1].Type);
                qr.Bind(Inventory.items[1].Ea);
                qr.Bind("SLOT2");
                qr.Step();
                qr.Release();
            }

            db.Close();

            GameObject.Find("GameDirector").GetComponent <AudioSource>().Stop();

            Application.LoadLevel("MainScene");
        }
        else
        {
            panelMessage.SetActive(true);
        }
    }
コード例 #4
0
    //
    //   INSERT CALLBACKS
    //
    //

    void InsertQueryCreated(SQLiteQuery qr, object state)
    {
        //
        // insert string and blob
        //
        qr.Bind(testString);
        qr.Bind(testBlob);

        // call step asynchronously
        asyncDB.Step(qr, InsertStepInvoked, state);
    }
コード例 #5
0
    static public void insertEmail(string email, string sessionId)
    {
        SQLiteQuery qr;
        string      queryInsertStats = "INSERT INTO emails (deviceId, email, sessionId, creationDate) VALUES(?,?,?,?);";

        string currentDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

        qr = new SQLiteQuery(db, queryInsertStats);
        qr.Bind(uniqueId);
        qr.Bind(email);
        qr.Bind(sessionId);
        qr.Bind(currentDateTime);
        qr.Step();
        qr.Release();
    }
コード例 #6
0
    public void InsertData(int slot_no,
                           string weapon_datacode,
                           int up_level,
                           int up_dur,
                           int up_attack,
                           float up_critical_ratio,
                           int upgrade_limit,
                           float up_attack_speed,
                           int class_no,
                           int count
                           )
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            // string strsql = string.Format(_queryUpdate_atk_cri_spd, a_idx); //
            qr = new SQLiteQuery(_db, _queryInsert);
            qr.Bind(slot_no);
            qr.Bind(weapon_datacode);
            qr.Bind(up_level);
            qr.Bind(up_dur);
            qr.Bind(up_attack);
            qr.Bind(up_critical_ratio);
            qr.Bind(upgrade_limit);
            qr.Bind(up_attack_speed);
            qr.Bind(class_no);
            qr.Bind(count);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #7
0
    public void Update_tutorial_play(int a_tutorial_play)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_SaveDB());
            SQLiteQuery qr;
            // string strsql = string.Format(_queryUpdate_exp
            qr = new SQLiteQuery(_db, _queryUpdate_tutorial_play);
            qr.Bind(a_tutorial_play);                                 //
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #8
0
ファイル: optionDB.cs プロジェクト: CoderBear/AAUnity
    public bool getStatus(int id)
    {
        bool result = false;
        int num;

        string dbFile = Application.persistentDataPath + "/optionDB_playmaker.db";
        SQLiteDB db = new SQLiteDB();

        db.Open(dbFile);
        SQLiteQuery qr = new SQLiteQuery(db, "SELECT result FROM option_table WHERE id=?");
        qr.Bind(id);
        qr.Step();
        num = qr.GetInteger("result");
        switch (num)
        {
            case 0:
                result = false;
                break;
            case 1:
                result = true;
                break;
        }

        qr.Release();
        db.Close();

        return result;
    }
コード例 #9
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
    public bool isUnlocked(int id)
    {
        bool result = false;
        int  num;

        string   dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
        SQLiteDB db     = new SQLiteDB();

        db.Open(dbFile);
        SQLiteQuery qr = new SQLiteQuery(db, "SELECT Unlocked FROM achieve_table WHERE id=?");

        qr.Bind(id);
        qr.Step();
        num = qr.GetInteger("Unlocked");
        switch (num)
        {
        case 0:
            result = false;
            break;

        case 1:
            result = true;
            break;
        }

        qr.Release();
        db.Close();

        return(result);
    }
コード例 #10
0
    public void Update_score(int a_score, int a_stage_no, int a_round_no)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            string      strsql = string.Format(_queryUpdate_score, a_stage_no, a_round_no); //

            qr = new SQLiteQuery(_db, strsql);
            qr.Bind(a_score);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
                _db = null;
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #11
0
    public void Update_total_exp(int a_val, string idx)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            string      strsql = string.Format(_queryUpdate_total_exp, idx); //

            qr = new SQLiteQuery(_db, strsql);
            qr.Bind(a_val);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
                _db = null;
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #12
0
    public void Update_weapon_datacode(string a_datacode, int a_idx)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            string      strsql = string.Format(_queryUpdate_weapon_datacode_where_idx, a_idx); //
            qr = new SQLiteQuery(_db, strsql);
            qr.Bind(a_datacode);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
            }
            UnityEngine.Debug.LogError(e.ToString());
        }
        return;
    }
コード例 #13
0
    public void Update_play_slot_no(int a_play_slot_no)
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try{
            _db.Open(GetFileName_SaveDB());

            SQLiteQuery qr;
            qr = new SQLiteQuery(_db, _queryUpdate_play_slot_no);
            qr.Bind(a_play_slot_no);
            qr.Step();
            qr.Release();
            _db.Close();
        } catch (Exception e) {
            if (_db != null)
            {
                _db.Close();
                _db = null;
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #14
0
    public void setHealthPackInfo(System.Object[] insertValues)
    {
        SQLiteQuery query;

        query = new SQLiteQuery(instance.db,
                                "UPDATE HealthPacks " +
                                "SET Amount_Owned = ? " +
                                "WHERE Pack_ID = ?"
                                );

        query.Bind((int)insertValues[0]);
        query.Bind((int)insertValues[1]);

        query.Step();

        query.Release();
    }
コード例 #15
0
    public void setUnlockStatus(string tableName, string idColumn, int idRow, int isPurchased)
    {
        SQLiteQuery query;

        query = new SQLiteQuery(instance.db,
                                "UPDATE " + tableName + " " +
                                "SET isPurchased = ? " +
                                "WHERE " + idColumn + " = ?"
                                );

        query.Bind((int)isPurchased);
        query.Bind((int)idRow);

        query.Step();

        query.Release();
    }
コード例 #16
0
    public void setGunInfo(System.Object[] insertValues)
    {
        SQLiteQuery query;

        query = new SQLiteQuery(instance.db,
                                "UPDATE Weapons " +
                                "SET isPurchased = ? " +
                                "WHERE Gun_ID = ?"
                                );

        query.Bind((int)insertValues[0]);
        query.Bind((int)insertValues[1]);

        query.Step();

        query.Release();
    }
コード例 #17
0
    public void setAmmoInfo(System.Object[] insertValues)
    {
        SQLiteQuery query;

        query = new SQLiteQuery(instance.db,
                                "UPDATE Compatible_Ammo " +
                                "SET isPurchased = ?, Amount_Owned = ? " +
                                "WHERE Ammo_ID = ?"
                                );

        query.Bind((int)insertValues[0]);
        query.Bind((int)insertValues[1]);
        query.Bind((int)insertValues[2]);

        query.Step();

        query.Release();
    }
コード例 #18
0
        public void Delete(string tableName, string key)
        {
            CreateTable(tableName);
            string      sql = @"DELETE FROM " + tableName + " WHERE key=?";
            SQLiteQuery qr  = new SQLiteQuery(_db, sql);

            qr.Bind(key);
            qr.Step();
            qr.Release();
        }
コード例 #19
0
    public void Update_all_where_idx(
        int a_idx,
        ST_S_PlayerWeaponRec rec
        )
    {
        if (_db == null)
        {
            _db = new SQLiteDB();
        }
        try
        {
            _db.Open(GetFileName_DB());

            SQLiteQuery qr;
            string      strsql = string.Format(_queryUpdate_all_where_idx, a_idx); //
            qr = new SQLiteQuery(_db, strsql);
            qr.Bind(rec.slot_no);
            qr.Bind(rec.weapon_datacode);
            qr.Bind(rec.up_level);
            qr.Bind(rec.up_dur);
            qr.Bind(rec.up_attack);
            qr.Bind(rec.up_critical_ratio);
            qr.Bind(rec.upgrade_limit);
            qr.Bind(rec.up_attack_speed);
            qr.Bind(rec.class_no);
            qr.Bind(rec.count);
            qr.Step();
            qr.Release();
            _db.Close();
        }
        catch (Exception e)
        {
            if (_db != null)
            {
                _db.Close();
            }
            UnityEngine.Debug.LogError(e.ToString());
        }

        return;
    }
コード例 #20
0
        void QueryComplete(SQLiteQuery qr, object state)
        {
            query = qr;
            if (qr == null)
            {
                Fsm.Event(onFail);
            }
            else
            {
                foreach (FsmStateAction action in State.Actions)
                {
                    SQLiteBindInteger bindInt = action as SQLiteBindInteger;
                    if (bindInt != null)
                    {
                        query.Bind(bindInt.integerValue.Value);
                    }

                    SQLiteBindBool bindBool = action as SQLiteBindBool;
                    if (bindBool != null)
                    {
                        query.Bind(bindBool.boolValue.Value ? 1:0);
                    }

                    SQLiteBindFloat bindFloat = action as SQLiteBindFloat;
                    if (bindFloat != null)
                    {
                        query.Bind((double)bindFloat.floatValue.Value);
                    }

                    SQLiteBindString bindStr = action as SQLiteBindString;
                    if (bindStr != null)
                    {
                        query.Bind(bindStr.stringValue.Value);
                    }
                }

                taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query, StepComplete, null);
            }
        }
コード例 #21
0
        public bool ContainKey(string tableName, string key)
        {
            CreateTable(tableName);
            string      sql = @"SELECT COUNT(id) as c FROM " + tableName + " WHERE key = ?";
            SQLiteQuery qr  = new SQLiteQuery(_db, sql);

            qr.Bind(key);
            qr.Step();
            int c = qr.GetInteger("c");

            qr.Release();
            return(c > 0);
        }
コード例 #22
0
		void QueryComplete(SQLiteQuery qr, object state)
		{
			query = qr;
			if(qr == null)
			{
				Fsm.Event(onFail);
			}
			else
			{
				foreach( FsmStateAction action in State.Actions )
				{
					SQLiteBindInteger bindInt = action as SQLiteBindInteger;
					if(bindInt != null)
					{
						query.Bind(bindInt.integerValue.Value);
					}
					
					SQLiteBindBool bindBool = action as SQLiteBindBool;
					if(bindBool != null)
					{
						query.Bind(bindBool.boolValue.Value ? 1:0);
					}
					
					SQLiteBindFloat bindFloat = action as SQLiteBindFloat;
					if(bindFloat != null)
					{
						query.Bind((double)bindFloat.floatValue.Value);
					}
					
					SQLiteBindString bindStr = action as SQLiteBindString;
					if(bindStr != null)
					{
						query.Bind(bindStr.stringValue.Value);
					}
				}
				
				taskCtrl = SQLiteManager.Instance.GetSQLiteAsync(shortcutName.Value).Step(query,StepComplete,null);
			}
		}
コード例 #23
0
        /// <summary>
        /// Add Or Update the specified tableName, key and value.
        /// </summary>
        /// <param name="tableName">Table name.</param>
        /// <param name="key">Key.</param>
        /// <param name="value">Value.</param>
        public void SetValue(string tableName, string key, string value)
        {
            CreateTable(tableName);
            string      sql = "";
            SQLiteQuery qr  = null;

            if (ContainKey(tableName, key))
            {
                sql = @"Update " + tableName + " SET value = ? where key = ?";
                qr  = new SQLiteQuery(_db, sql);
                qr.Bind(value);
                qr.Bind(key);
            }
            else
            {
                sql = @"INSERT INTO " + tableName + " (key, value) VALUES (?,?);";
                qr  = new SQLiteQuery(_db, sql);
                qr.Bind(key);
                qr.Bind(value);
            }
            qr.Step();
            qr.Release();
        }
コード例 #24
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
	public string getName(int id) {
		string name = "";
		string dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
		SQLiteDB db = new SQLiteDB();
		
		db.Open(dbFile);
		SQLiteQuery qr = new SQLiteQuery(db, "SELECT Name FROM achieve_table WHERE id=?");
		qr.Bind(id);
		while (qr.Step()) {
			name = qr.GetString("Name");
		}
		qr.Release();
		db.Close();
		return name;
	}
コード例 #25
0
ファイル: MobDB.cs プロジェクト: CoderBear/ARG-Zombies
	public int getMoney(int id) {
		int num = 0;
		string dbFile = Application.persistentDataPath + "/mobDB.db";
		SQLiteDB db = new SQLiteDB ();
		
		db.Open (dbFile);
		SQLiteQuery qr = new SQLiteQuery (db, "SELECT money FROM mob_info WHERE id=?");
		qr.Bind (id);
		qr.Step ();
		num = qr.GetInteger ("money");
		qr.Release ();
		db.Close ();
		
		return num;
	}
コード例 #26
0
        public bool Bind(SQLiteQuery qr, string strValue)
        {
            if (String.Compare(strValue, ":null", true) == 0)
            {
                qr.BindNull();
            }
            else
            {
                switch (type)
                {
                case Type.Text:
                    qr.Bind(strValue);
                    break;

                case Type.Integer:
                    qr.Bind(int.Parse(strValue));
                    break;

                default:
                    return(false);
                }
            }
            return(true);
        }
コード例 #27
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
	public int getTarget(int id) {
		int num = 0;
		
		string dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
		SQLiteDB db = new SQLiteDB();
		
		db.Open(dbFile);
		SQLiteQuery qr = new SQLiteQuery(db, "SELECT Target FROM achieve_table WHERE id=?");
		qr.Bind(id);
		qr.Step();
		num = qr.GetInteger("Target");
		qr.Release();
		db.Close();
		
		return num;
	}
コード例 #28
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
	public string getDesc(int id) {
		string description = "";
		
		string dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
		SQLiteDB db = new SQLiteDB();
		
		db.Open(dbFile);
		SQLiteQuery qr = new SQLiteQuery(db, "SELECT Description FROM achieve_table WHERE id=?");
		qr.Bind(id);
		while (qr.Step()) {
			description = qr.GetString("Description");
		}
		qr.Release();
		db.Close();
		
		return description;
	}
コード例 #29
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
    public int getTarget(int id)
    {
        int num = 0;

        string   dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
        SQLiteDB db     = new SQLiteDB();

        db.Open(dbFile);
        SQLiteQuery qr = new SQLiteQuery(db, "SELECT Target FROM achieve_table WHERE id=?");

        qr.Bind(id);
        qr.Step();
        num = qr.GetInteger("Target");
        qr.Release();
        db.Close();

        return(num);
    }
コード例 #30
0
ファイル: StatsDB.cs プロジェクト: CoderBear/AAUnity
	public int getValue (string name)
	{
		int num = 0;
		string filename = Application.persistentDataPath + "/statsDB_playmaker.db";
					
		SQLiteDB db = new SQLiteDB ();
		SQLiteQuery qr;
		string query = "SELECT value FROM stats_table WHERE name =?";
		db.Open (filename);
		qr = new SQLiteQuery (db, query);
		qr.Bind (name);
		qr.Step ();
		num = qr.GetInteger ("value");
		qr.Release ();
		db.Close ();
		
		return num;
	}
コード例 #31
0
ファイル: AchieveDB.cs プロジェクト: CoderBear/AAUnity
    public string getName(int id)
    {
        string   name   = "";
        string   dbFile = Application.persistentDataPath + "/achieveDB_playmaker.db";
        SQLiteDB db     = new SQLiteDB();

        db.Open(dbFile);
        SQLiteQuery qr = new SQLiteQuery(db, "SELECT Name FROM achieve_table WHERE id=?");

        qr.Bind(id);
        while (qr.Step())
        {
            name = qr.GetString("Name");
        }
        qr.Release();
        db.Close();
        return(name);
    }
コード例 #32
0
    public int getValue(string name)
    {
        int    num      = 0;
        string filename = Application.persistentDataPath + "/statsDB_playmaker.db";

        SQLiteDB    db = new SQLiteDB();
        SQLiteQuery qr;
        string      query = "SELECT value FROM stats_table WHERE name =?";

        db.Open(filename);
        qr = new SQLiteQuery(db, query);
        qr.Bind(name);
        qr.Step();
        num = qr.GetInteger("value");
        qr.Release();
        db.Close();

        return(num);
    }
コード例 #33
0
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <returns>The value.</returns>
        /// <param name="tableName">Table name.</param>
        /// <param name="key">Key.</param>
        public string GetValue(string tableName, string key, string defaultValue)
        {
            CreateTable(tableName);

            if (!ContainKey(tableName, key))
            {
                return(defaultValue);
            }
            string      value = null;
            string      sql   = @"SELECT value FROM " + tableName + " WHERE key = ?";
            SQLiteQuery qr    = new SQLiteQuery(_db, sql);

            qr.Bind(key);
            if (qr.Step())
            {
                try{
                    value = qr.GetString("value");
                }catch {
                    Debug.LogError("SQLITE>>" + tableName + "   Key:" + key + "   是Null数据");
                }
            }
            qr.Release();
            return(value);
        }
コード例 #34
0
	void Test( SQLiteDB db, ref string log )
	{
		SQLiteQuery qr;
		
		
		//
		// delete table if exists
		//
		qr = new SQLiteQuery(db, queryDelete);
		qr.Step();												
		qr.Release();                                        log += "\nTable deleted.";
		
		//
		// create table
		//
		qr = new SQLiteQuery(db, queryCreate); 
		qr.Step();												
		qr.Release();                                        log += "\nTable created.";
		
		//
		// insert string and blob
		//
		qr = new SQLiteQuery(db, queryInsert); 
		qr.Bind(testString);
		qr.Bind(testBlob);
		qr.Step();
		qr.Release();                                        log += "\nInsert test string and blob.";
		
		//
		// read strings
		//
		string testStringFromSelect = "";
		qr = new SQLiteQuery(db, querySelect); 
		while( qr.Step() )
		{
			testStringFromSelect = qr.GetString("str_field");
			if( testStringFromSelect != testString )
			{
				throw new Exception( "Test string are not equal!" );
			}
			
			byte[] testBlobFromSelect = qr.GetBlob("blob_field");
			
			if( testBlobFromSelect.Length != testBlob.Length )
			{
				throw new Exception( "Test blobs are not equal!" );
			}
			
			for (int i = 0; i < testBlobFromSelect.Length; i++)
			{
				if( testBlobFromSelect[i] != testBlob[i] )
				{
					throw new Exception( "Test blobs are not equal!" );
				}
			}
		}
		if( testStringFromSelect == "" )
		{
			throw new Exception( "Unknowm problem!" );
		}
		qr.Release();                                        log += "\nRead and test strings and blobs.";

		//
		//
		// delete table
		//
		qr = new SQLiteQuery(db, queryDelete);
		qr.Step();												
		qr.Release();                                        log += "\nTable deleted.";
		
		//
		// if we reach that point it's mean we pass the test!
		db.Close();                                           log += "\nDatabase closed!\nTest succeeded!";

	}
コード例 #35
0
ファイル: DemoObject3.cs プロジェクト: CoderBear/ARG-Zombies
	void Update () {
	
		if(test == true)		
		{
			
			test = false;
			
			SQLiteQuery qr = null;
			SQLiteDB db = null;
			
			try{
				db = new SQLiteDB();
				db.Open(FILE);
				
				db.Key("0x0102030405060708090a0b0c0d0e0f10");
				// or
				//qr = new SQLiteQuery(db, queryKey); 
				//qr.Step();
				//qr.Release();
				//qr = null;
				
				qr = new SQLiteQuery(db,queryCreate);
				qr.Step();
				qr.Release();
				qr = null;
				
				
				qr = new SQLiteQuery(db,queryCreate2);
				qr.Step();
				qr.Release();
				qr = null;
					
				qr = new SQLiteQuery(db, queryInsert); 
				qr.Bind(testString);
				qr.Bind(testBlob);
				qr.Step();
				qr.Step();
				qr.Step();
				qr.Release();
				qr = null;

				
				db.Close();
				db = null;
				
				
				UnityEngine.Debug.Log("Close and open again.");
	
				
				db = new SQLiteDB();
				db.Open(FILE);
				
				db.Key("0x0102030405060708090a0b0c0d0e0f10");
				// or
				//qr = new SQLiteQuery(db, queryKey); 
				//qr.Step();
				//qr.Release();
				//qr = null;
					
				qr = new SQLiteQuery(db,queryCreate3);
				qr.Step();
				qr.Release();
				qr = null;
					
				qr = new SQLiteQuery(db, queryInsert); 
				qr.Bind(testString);
				qr.Bind(testBlob);
				qr.Step();
				qr.Step();
				qr.Step();
				qr.Release();
				qr = null;
				
				String testString2;
				qr = new SQLiteQuery(db, querySelect); 
				while(qr.Step())
				{
					testString2 = qr.GetString("str_field");
					testString2.ToString();
				}
				qr.Release();
				qr = null;
	
				db.Close();
				
				db = null;
				
				UnityEngine.Debug.Log("Done");
			}catch(Exception e)
			{
				UnityEngine.Debug.LogError(e.Message);
				
				if(qr!=null)
					qr.Release();
				qr = null;
				if(db!=null)
					db.Close();
				db=null;
			}

		}
		
	}
コード例 #36
0
ファイル: DemoObject2.cs プロジェクト: Avatarchik/Duel-Off
	// 
	//   INSERT CALLBACKS
	//
	//

	void InsertQueryCreated(SQLiteQuery qr, object state)
	{
		//
		// insert string and blob
		//
		qr.Bind(testString);
		qr.Bind(testBlob);
		
		// call step asynchronously 
		asyncDB.Step(qr, InsertStepInvoked, state);
	}
コード例 #37
0
	void OnGUI()
	{
		if( db == null )
		{
			if ( GUI.Button(new Rect (10,10,150,50), "Run SQLite Test \nat persistentDataPath") ) 
			{
				db = new SQLiteDB();
				
				string filename = Application.persistentDataPath + "/demo_1.db";
				
				log = "";
				
				try{
					//
					// initialize database
					//
					db.Open(filename);                               log += "Database created! filename:"+filename;
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n on WebPlayer it must give an exception, it's normal.";
				}
			}
			if ( GUI.Button(new Rect (10,70,150,70), "Run SQLite Test \nat :memory:\nbest for cache") ) 
			{
				
				db = new SQLiteDB();
				
				log = "";
				
				try{
					
					//
					// initialize database
					//
					db.OpenInMemory();                               log += "Database created! in :memory:";
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
			}
			
			if ( GUI.Button(new Rect (10,150,150,70), "Run SQLite Test \nwith stream\nbest for WebPlayer") ) 
			{
				
				db = new SQLiteDB();
				
				MemoryStream memStream = new MemoryStream();
				
				log = "";
				
				try{
					
					//
					// initialize database
					//
					db = new SQLiteDB();
					db.OpenStream("stream1",memStream);                               log += "Database created! named stream: stream1";
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
			}
			
			if ( GUI.Button(new Rect (10,230,150,70), "Run SQLite Test \nwith streamingAssets") ) 
			{
				
				db = new SQLiteDB();
				
				log = "";
				
				string dbfilename = "test.db";
	
				byte[] bytes = null;				
				
				
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
				string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#elif UNITY_WEBPLAYER
				string dbpath = "StreamingAssets/" + dbfilename;								log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#elif UNITY_IPHONE
				string dbpath = Application.dataPath + "/Raw/" + dbfilename;					log += "asset path is: " + dbpath;					
				try{	
					using ( FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read) ){
						bytes = new byte[fs.Length];
						fs.Read(bytes,0,(int)fs.Length);
					}			
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
#elif UNITY_ANDROID
				string dbpath = Application.streamingAssetsPath + "/" + dbfilename;	            log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#endif
				if ( bytes != null )
				{
					
					try{	
						//
						// create and write the asset into memory stream
						//
						MemoryStream memStream = new MemoryStream();
						
						memStream.Write(bytes,0,bytes.Length);
						
						//
						// initialize database
						//
						db.OpenStream("stream2",memStream);                               log += "\nDatabase created! named stream: stream2";
						
						Test2(db, ref log);
						
					} catch (Exception e){
						log += 	"\nTest Fail with Exception " + e.ToString();
						log += 	"\n\n Did you copy test.db into StreamingAssets ?\n";
					}
				}
			}

			
			if ( GUI.Button(new Rect (170,10,150,70), "Run SQLite Test \nfor streamingAssets db\nwhich moved to \npersistentDataPath") ) 
			{
				
				db = new SQLiteDB();
				
				log = "";
				
				string dbfilename = "test.db";
	
				byte[] bytes = null;				
				
				
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
				string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#elif UNITY_WEBPLAYER
				string dbpath = "StreamingAssets/" + dbfilename;								log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#elif UNITY_IPHONE
				string dbpath = Application.dataPath + "/Raw/" + dbfilename;					log += "asset path is: " + dbpath;					
				try{	
					using ( FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read) ){
						bytes = new byte[fs.Length];
						fs.Read(bytes,0,(int)fs.Length);
					}			
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
#elif UNITY_ANDROID
				string dbpath = Application.streamingAssetsPath + "/" + dbfilename;	            log += "asset path is: " + dbpath;
				WWW www = new WWW(dbpath);
				Download(www);
				bytes = www.bytes;
#endif
				if ( bytes != null )
				{
					try{	
						
						string filename = Application.persistentDataPath + "/demo_from_streamingAssets.db";

						//
						//
						// copy database to real file into cache folder
						using( FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write) )
						{
							fs.Write(bytes,0,bytes.Length);             log += "\nCopy database from streaminAssets to persistentDataPath: " + filename;
						}
						
						//
						// initialize database
						//
						db.Open(filename);                               log += "\nDatabase created! filename: " + filename;
						
						Test2(db, ref log);
						
					} catch (Exception e){
						log += 	"\nTest Fail with Exception " + e.ToString();
						log += 	"\n\n Did you copy test.db into StreamingAssets ?\n";
					}
				}
			}

			
			
			//
			// Very common scenario for most products.
			// 
			
			if ( GUI.Button(new Rect (170,90,150,70), "Run SQLite\nfor real project scenario") ) 
			{
				
				db = new SQLiteDB();
				
				log = "";

				// a product persistant database path.
				string filename = Application.persistentDataPath + "/demo_from_streamingAssets2.db";
				
				// check if database already exists.
				
				if(!File.Exists(filename))
				{
					
					// ok , this is first time application start!
					// so lets copy prebuild dtabase from StreamingAssets and load store to persistancePath with Test2
									
					string dbfilename = "test.db";
		
					byte[] bytes = null;				
					
					
	#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
					string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
					WWW www = new WWW(dbpath);
					Download(www);
					bytes = www.bytes;
	#elif UNITY_WEBPLAYER
					string dbpath = "StreamingAssets/" + dbfilename;								log += "asset path is: " + dbpath;
					WWW www = new WWW(dbpath);
					Download(www);
					bytes = www.bytes;
	#elif UNITY_IPHONE
					string dbpath = Application.dataPath + "/Raw/" + dbfilename;					log += "asset path is: " + dbpath;					
					try{	
						using ( FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read) ){
							bytes = new byte[fs.Length];
							fs.Read(bytes,0,(int)fs.Length);
						}			
					} catch (Exception e){
						log += 	"\nTest Fail with Exception " + e.ToString();
						log += 	"\n";
					}
	#elif UNITY_ANDROID
					string dbpath = Application.streamingAssetsPath + "/" + dbfilename;	            log += "asset path is: " + dbpath;
					WWW www = new WWW(dbpath);
					Download(www);
					bytes = www.bytes;
	#endif
					if ( bytes != null )
					{
						try{	
							
							//
							//
							// copy database to real file into cache folder
							using( FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write) )
							{
								fs.Write(bytes,0,bytes.Length);             log += "\nCopy database from streaminAssets to persistentDataPath: " + filename;
							}
							
							//
							// initialize database
							//
							db.Open(filename);                               log += "\nDatabase created! filename: " + filename;
							
							Test2(db, ref log);
							
						} catch (Exception e){
							log += 	"\nTest Fail with Exception " + e.ToString();
							log += 	"\n\n Did you copy test.db into StreamingAssets ?\n";
						}
					}
				}
				else
				{
					// it mean we already download prebuild data base and store into persistantPath
					// lest update, I will call Test
					
					try{
						//
						// initialize database
						//
						db.Open(filename);                               log += "Database created! filename:"+filename;
						
						Test(db, ref log);
						
					} catch (Exception e){
						log += 	"\nTest Fail with Exception " + e.ToString();
						log += 	"\n on WebPlayer it must give an exception, it's normal.";
					}
					
				}
			}
#if ENCRYPTION
			//
			// ENCRYPTION
			// 
			
			if ( GUI.Button(new Rect (170,170,150,70), "Run SQLite\nfor ENCRYPTION scenario") ) 
			{
				
				try {
					
					db = new SQLiteDB();
					
					log = "";
	
					// a product persistant database path.
					string filename = Application.persistentDataPath + "/demo_from_encryption.db";
					
					File.Delete(filename);
					
					db.Open(filename);
	
					
					//
					// set ENCRYPTION
					//
					SQLiteQuery qr = new SQLiteQuery(db,"PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
					qr.Step();
					qr.Release();
						
					//
					// create table
					//
					qr = new SQLiteQuery(db, queryCreate); 
					qr.Step();												
					qr.Release();                                        log += "\nTable created.";
					
					//
					// insert string and blob
					//
					qr = new SQLiteQuery(db, queryInsert); 
					qr.Bind(testString);
					qr.Bind(testBlob);
					qr.Step();
					qr.Release();                                        log += "\nInsert test string and blob.";
					
					
					// close
					db.Close();
										
					// and open again
					db.Open(filename);
					
					//
					// set ENCRYPTION AGAIN, you could  try change to see ENCRYPTION works
					//
					qr = new SQLiteQuery(db,"PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
					qr.Step();
					qr.Release();
					
					// do test
					Test2( db, ref log );
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n on WebPlayer it must give an exception, it's normal.";
				}
			}
#endif
		}
		else
		{
			if ( GUI.Button(new Rect (10,10,150,50), "Back") ) 
			{
				db = null;
			}
			GUI.Label (new Rect (10,70,600,600), log);
		}
	}
コード例 #38
0
ファイル: DemoObject.cs プロジェクト: CoderBear/ARG-Zombies
	void OnGUI()
	{
		if( db == null )
		{
			if ( GUI.Button(new Rect (10,10,150,50), "Run SQLite Test \nat persistentDataPath") ) 
			{
				db = new SQLiteDB();
				
				string filename = Application.persistentDataPath + "/demo_1.db";
				
				log = "";
				
				try{
					//
					// initialize database
					//
					db.Open(filename);                               log += "Database created! filename:"+filename;
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n on WebPlayer it must give an exception, it's normal.";
				}
			}
			if ( GUI.Button(new Rect (10,70,150,70), "Run SQLite Test \nat :memory:\nbest for cache") ) 
			{
				
				db = new SQLiteDB();
				
				log = "";
				
				try{
					
					//
					// initialize database
					//
					db.OpenInMemory();                               log += "Database created! in :memory:";
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
			}
			
			if ( GUI.Button(new Rect (10,150,150,70), "Run SQLite Test \nwith stream\nbest for WebPlayer") ) 
			{
				
				db = new SQLiteDB();
				
				MemoryStream memStream = new MemoryStream();
				
				log = "";
				
				try{
					
					//
					// initialize database
					//
					db = new SQLiteDB();
					db.OpenStream("stream1",memStream);                               log += "Database created! named stream: stream1";
					
					Test(db, ref log);
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n";
				}
			}
			
			if ( GUI.Button(new Rect (10,230,150,70), "Run SQLite Test \nwith streamingAssets") ) 
			{
				
				StartCoroutine(TestWithStreamingAssets());
				
			}

			
			if ( GUI.Button(new Rect (170,10,150,70), "Run SQLite Test \nfor streamingAssets db\nwhich moved to \npersistentDataPath") ) 
			{
				
				StartCoroutine(TestWithStreamingAssetsCopiedToPersistentDataPath());
				
			}

			
			//
			// Very common scenario for most products.
			// 
			
			if ( GUI.Button(new Rect (170,90,150,70), "Run SQLite\nfor real project scenario") ) 
			{
				
				StartCoroutine(TestBestForRealProject());
				
			}
#if ENCRYPTION
			//
			// ENCRYPTION
			// 
			
			if ( GUI.Button(new Rect (170,170,150,70), "Run SQLite\nfor ENCRYPTION scenario") ) 
			{
				
				try {
					
					db = new SQLiteDB();
					
					log = "";
	
					// a product persistant database path.
					string filename = Application.persistentDataPath + "/demo_from_encryption.db";
					
					File.Delete(filename);
					
					db.Open(filename);
	
					
					//
					// set ENCRYPTION
					//
					SQLiteQuery qr = new SQLiteQuery(db,"PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
					qr.Step();
					qr.Release();
						
					//
					// create table
					//
					qr = new SQLiteQuery(db, queryCreate); 
					qr.Step();												
					qr.Release();                                        log += "\nTable created.";
					
					//
					// insert string and blob
					//
					qr = new SQLiteQuery(db, queryInsert); 
					qr.Bind(testString);
					qr.Bind(testBlob);
					qr.Step();
					qr.Release();                                        log += "\nInsert test string and blob.";
					
					
					// close
					db.Close();
										
					// and open again
					db.Open(filename);
					
					//
					// set ENCRYPTION AGAIN, you could  try change to see ENCRYPTION works
					//
					qr = new SQLiteQuery(db,"PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
					qr.Step();
					qr.Release();
					
					// do test
					Test2( db, ref log );
					
				} catch (Exception e){
					log += 	"\nTest Fail with Exception " + e.ToString();
					log += 	"\n on WebPlayer it must give an exception, it's normal.";
				}
			}
#endif
			
			//
			// PlayerPrefs
			// 
			
			if ( GUI.Button(new Rect (170,250,150,50), "Copy db to\n PlayerPrefs") ) 
			{
				
				StartCoroutine(CopyDB2PlayerPrefs());
								
			}
			
			
			
			if ( GUI.Button(new Rect (170,310,150,50), "Run SQLite Test \nfor PlayerPrefs") ) 
			{
				
				db = new SQLiteDB();
				
				MemoryStream memStream = new MemoryStream();
				
				log = "";
				
				string testdbz = PlayerPrefs.GetString("sqlitedb");
				
				log += "Read Database from PlayerPrefs! : " + testdbz.Substring(0,64) + "...\n";
				
				if(testdbz.Length > 0)
				{
					
					for(int i=0; i*2<testdbz.Length; i++)
					{
						memStream.WriteByte(Convert.ToByte(testdbz.Substring(i*2,2),16));
					}
					
					try{
						
						//
						// initialize database
						//
						db = new SQLiteDB();
						db.OpenStream("stream3",memStream);                               log += "Database created from PlayerPrefs! named stream: stream3";
						
						Test2(db, ref log);
						
					} catch (Exception e){
						log += 	"\nTest Fail with Exception " + e.ToString();
						log += 	"\n";
					}
					
				}
				else
				{
					log += "Please push button above to put database into PlayerPrefs!\n";
				}
			}

			
			
			
		}
		else
		{
			if ( GUI.Button(new Rect (10,10,150,50), "Back") ) 
			{
				db = null;
			}
			GUI.Label (new Rect (10,70,600,600), log);
		}
	}
コード例 #39
0
    void OnGUI()
    {
        if (db == null)
        {
            if (GUI.Button(new Rect(10, 10, 150, 50), "Run SQLite Test \nat persistentDataPath"))
            {
                db = new SQLiteDB();

                string filename = ExtensionMethods.AppWritableDirectory() + "/demo_1.db";

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db.Open(filename);                               log += "Database created! filename:" + filename;

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n on WebPlayer it must give an exception, it's normal.";
                }
            }
            if (GUI.Button(new Rect(10, 70, 150, 70), "Run SQLite Test \nat :memory:\nbest for cache"))
            {
                db = new SQLiteDB();

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db.OpenInMemory();                               log += "Database created! in :memory:";

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
            }

            if (GUI.Button(new Rect(10, 150, 150, 70), "Run SQLite Test \nwith stream\nbest for WebPlayer"))
            {
                db = new SQLiteDB();

                MemoryStream memStream = new MemoryStream();

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db = new SQLiteDB();
                    db.OpenStream("stream1", memStream);                               log += "Database created! named stream: stream1";

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
            }

            if (GUI.Button(new Rect(10, 230, 150, 70), "Run SQLite Test \nwith streamingAssets"))
            {
                StartCoroutine(TestWithStreamingAssets());
            }


            if (GUI.Button(new Rect(170, 10, 150, 70), "Run SQLite Test \nfor streamingAssets db\nwhich moved to \npersistentDataPath"))
            {
                StartCoroutine(TestWithStreamingAssetsCopiedToPersistentDataPath());
            }


            //
            // Very common scenario for most products.
            //

            if (GUI.Button(new Rect(170, 90, 150, 70), "Run SQLite\nfor real project scenario"))
            {
                StartCoroutine(TestBestForRealProject());
            }
#if ENCRYPTION
            //
            // ENCRYPTION
            //

            if (GUI.Button(new Rect(170, 170, 150, 70), "Run SQLite\nfor ENCRYPTION scenario"))
            {
                try {
                    db = new SQLiteDB();

                    log = "";

                    // a product persistant database path.
                    string filename = ExtensionMethods.AppWritableDirectory() + "/demo_from_encryption.db";

                    File.Delete(filename);

                    db.Open(filename);


                    //
                    // set ENCRYPTION
                    //
                    SQLiteQuery qr = new SQLiteQuery(db, "PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
                    qr.Step();
                    qr.Release();

                    //
                    // create table
                    //
                    qr = new SQLiteQuery(db, queryCreate);
                    qr.Step();
                    qr.Release();                                        log += "\nTable created.";

                    //
                    // insert string and blob
                    //
                    qr = new SQLiteQuery(db, queryInsert);
                    qr.Bind(testString);
                    qr.Bind(testBlob);
                    qr.Step();
                    qr.Release();                                        log += "\nInsert test string and blob.";


                    // close
                    db.Close();

                    // and open again
                    db.Open(filename);

                    //
                    // set ENCRYPTION AGAIN, you could  try change to see ENCRYPTION works
                    //
                    qr = new SQLiteQuery(db, "PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
                    qr.Step();
                    qr.Release();

                    // do test
                    Test2(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n on WebPlayer it must give an exception, it's normal.";
                }
            }
#endif

            //
            // PlayerPrefs
            //

            if (GUI.Button(new Rect(170, 250, 150, 50), "Copy db to\n PlayerPrefs"))
            {
                StartCoroutine(CopyDB2PlayerPrefs());
            }



            if (GUI.Button(new Rect(170, 310, 150, 50), "Run SQLite Test \nfor PlayerPrefs"))
            {
                db = new SQLiteDB();

                MemoryStream memStream = new MemoryStream();

                log = "";

                string testdbz = PlayerPrefs.GetString("sqlitedb");

                log += "Read Database from PlayerPrefs! : " + testdbz.Substring(0, 64) + "...\n";

                if (testdbz.Length > 0)
                {
                    for (int i = 0; i *2 < testdbz.Length; i++)
                    {
                        memStream.WriteByte(Convert.ToByte(testdbz.Substring(i * 2, 2), 16));
                    }

                    try{
                        //
                        // initialize database
                        //
                        db = new SQLiteDB();
                        db.OpenStream("stream3", memStream);                               log += "Database created from PlayerPrefs! named stream: stream3";

                        Test2(db, ref log);
                    } catch (Exception e) {
                        log += "\nTest Fail with Exception " + e.ToString();
                        log += "\n";
                    }
                }
                else
                {
                    log += "Please push button above to put database into PlayerPrefs!\n";
                }
            }
        }
        else
        {
            if (GUI.Button(new Rect(10, 10, 150, 50), "Back"))
            {
                db = null;
            }
            GUI.Label(new Rect(10, 70, 600, 600), log);
        }
    }
コード例 #40
0
    void Update()
    {
        if (test == true)
        {
            test = false;

            SQLiteQuery qr = null;
            SQLiteDB    db = null;

            try{
                db = new SQLiteDB();
                db.Open(FILE);

                //db.Key("0x0102030405060708090a0b0c0d0e0f10");
                // or
                //qr = new SQLiteQuery(db, queryKey);
                //qr.Step();
                //qr.Release();
                //qr = null;

                qr = new SQLiteQuery(db, queryCreate);
                qr.Step();
                qr.Release();
                qr = null;


                qr = new SQLiteQuery(db, queryCreate2);
                qr.Step();
                qr.Release();
                qr = null;

                qr = new SQLiteQuery(db, queryInsert);
                qr.Bind(testString);
                qr.Bind(testBlob);
                qr.Step();
                qr.Step();
                qr.Step();
                qr.Release();
                qr = null;


                db.Close();
                db = null;


                UnityEngine.Debug.Log("Close and open again.");


                db = new SQLiteDB();
                db.Open(FILE);

                db.Key("0x0102030405060708090a0b0c0d0e0f10");
                // or
                //qr = new SQLiteQuery(db, queryKey);
                //qr.Step();
                //qr.Release();
                //qr = null;

                qr = new SQLiteQuery(db, queryCreate3);
                qr.Step();
                qr.Release();
                qr = null;

                qr = new SQLiteQuery(db, queryInsert);
                qr.Bind(testString);
                qr.Bind(testBlob);
                qr.Step();
                qr.Step();
                qr.Step();
                qr.Release();
                qr = null;

                String testString2;
                qr = new SQLiteQuery(db, querySelect);
                while (qr.Step())
                {
                    testString2 = qr.GetString("str_field");
                    testString2.ToString();
                }
                qr.Release();
                qr = null;

                db.Close();

                db = null;

                UnityEngine.Debug.Log("Done");
            }catch (Exception e)
            {
                UnityEngine.Debug.LogError(e.Message);

                if (qr != null)
                {
                    qr.Release();
                }
                qr = null;
                if (db != null)
                {
                    db.Close();
                }
                db = null;
            }
        }
    }
コード例 #41
0
ファイル: SQLiteKitEditor.cs プロジェクト: hanahanaside/JPN
		public bool Bind( SQLiteQuery qr, string strValue )
		{
			if(String.Compare(strValue,":null",true)==0)
			{
				qr.BindNull();
			}
			else
			{
				switch(type)
				{
				case Type.Text:
					qr.Bind(strValue);
					break;
				case Type.Integer:
					qr.Bind(int.Parse(strValue));
					break;
				default:
					return false;
				}
			}
			return true;
		}
コード例 #42
0
ファイル: PlayerDB.cs プロジェクト: CoderBear/ARG-Zombies
	public int getInit(int id) {
		int num = 0;
		string dbFile = Application.persistentDataPath + "/playerDB.db";
		SQLiteDB db = new SQLiteDB ();
		
		db.Open (dbFile);
		SQLiteQuery qr = new SQLiteQuery (db, "SELECT init FROM player_info WHERE id=?");
		qr.Bind (id);
		qr.Step ();
		num = qr.GetInteger ("init");
		qr.Release ();
		db.Close (); 
		
		return num;
	}
コード例 #43
0
ファイル: DemoObject.cs プロジェクト: led-os/unity_kidsgame
    void OnGUI()
    {
        if (db == null)
        {
            if (GUI.Button(new Rect(10, 10, 150, 50), "Run SQLite Test \nat persistentDataPath"))
            {
                db = new SQLiteDB();

                string filename = Application.persistentDataPath + "/demo_1.db";

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db.Open(filename);                               log += "Database created! filename:" + filename;

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n on WebPlayer it must give an exception, it's normal.";
                }
            }
            if (GUI.Button(new Rect(10, 70, 150, 70), "Run SQLite Test \nat :memory:\nbest for cache"))
            {
                db = new SQLiteDB();

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db.OpenInMemory();                               log += "Database created! in :memory:";

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
            }

            if (GUI.Button(new Rect(10, 150, 150, 70), "Run SQLite Test \nwith stream\nbest for WebPlayer"))
            {
                db = new SQLiteDB();

                MemoryStream memStream = new MemoryStream();

                log = "";

                try{
                    //
                    // initialize database
                    //
                    db = new SQLiteDB();
                    db.OpenStream("stream1", memStream);                               log += "Database created! named stream: stream1";

                    Test(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
            }

            if (GUI.Button(new Rect(10, 230, 150, 70), "Run SQLite Test \nwith streamingAssets"))
            {
                db = new SQLiteDB();

                log = "";

                string dbfilename = "test.db";

                byte[] bytes = null;


#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
                string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#elif UNITY_WEBPLAYER
                string dbpath = "StreamingAssets/" + dbfilename;                                                                log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#elif UNITY_IPHONE
                string dbpath = Application.dataPath + "/Raw/" + dbfilename;                                    log += "asset path is: " + dbpath;
                try{
                    using (FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read)){
                        bytes = new byte[fs.Length];
                        fs.Read(bytes, 0, (int)fs.Length);
                    }
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
#elif UNITY_ANDROID
                string dbpath = Application.streamingAssetsPath + "/" + dbfilename;                 log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#endif
                if (bytes != null)
                {
                    try{
                        //
                        // create and write the asset into memory stream
                        //
                        MemoryStream memStream = new MemoryStream();

                        memStream.Write(bytes, 0, bytes.Length);

                        //
                        // initialize database
                        //
                        db.OpenStream("stream2", memStream);                               log += "\nDatabase created! named stream: stream2";

                        Test2(db, ref log);
                    } catch (Exception e) {
                        log += "\nTest Fail with Exception " + e.ToString();
                        log += "\n\n Did you copy test.db into StreamingAssets ?\n";
                    }
                }
            }


            if (GUI.Button(new Rect(170, 10, 150, 70), "Run SQLite Test \nfor streamingAssets db\nwhich moved to \npersistentDataPath"))
            {
                db = new SQLiteDB();

                log = "";

                string dbfilename = "test.db";

                byte[] bytes = null;


#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
                string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#elif UNITY_WEBPLAYER
                string dbpath = "StreamingAssets/" + dbfilename;                                                                log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#elif UNITY_IPHONE
                string dbpath = Application.dataPath + "/Raw/" + dbfilename;                                    log += "asset path is: " + dbpath;
                try{
                    using (FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read)){
                        bytes = new byte[fs.Length];
                        fs.Read(bytes, 0, (int)fs.Length);
                    }
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n";
                }
#elif UNITY_ANDROID
                string dbpath = Application.streamingAssetsPath + "/" + dbfilename;                 log += "asset path is: " + dbpath;
                WWW    www    = new WWW(dbpath);
                Download(www);
                bytes = www.bytes;
#endif
                if (bytes != null)
                {
                    try{
                        string filename = Application.persistentDataPath + "/demo_from_streamingAssets.db";

                        //
                        //
                        // copy database to real file into cache folder
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            fs.Write(bytes, 0, bytes.Length);             log += "\nCopy database from streaminAssets to persistentDataPath: " + filename;
                        }

                        //
                        // initialize database
                        //
                        db.Open(filename);                               log += "\nDatabase created! filename: " + filename;

                        Test2(db, ref log);
                    } catch (Exception e) {
                        log += "\nTest Fail with Exception " + e.ToString();
                        log += "\n\n Did you copy test.db into StreamingAssets ?\n";
                    }
                }
            }



            //
            // Very common scenario for most products.
            //

            if (GUI.Button(new Rect(170, 90, 150, 70), "Run SQLite\nfor real project scenario"))
            {
                db = new SQLiteDB();

                log = "";

                // a product persistant database path.
                string filename = Application.persistentDataPath + "/demo_from_streamingAssets2.db";

                // check if database already exists.

                if (!File.Exists(filename))
                {
                    // ok , this is first time application start!
                    // so lets copy prebuild dtabase from StreamingAssets and load store to persistancePath with Test2

                    string dbfilename = "test.db";

                    byte[] bytes = null;


        #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
                    string dbpath = "file://" + Application.streamingAssetsPath + "/" + dbfilename; log += "asset path is: " + dbpath;
                    WWW    www    = new WWW(dbpath);
                    Download(www);
                    bytes = www.bytes;
        #elif UNITY_WEBPLAYER
                    string dbpath = "StreamingAssets/" + dbfilename;                                                                log += "asset path is: " + dbpath;
                    WWW    www    = new WWW(dbpath);
                    Download(www);
                    bytes = www.bytes;
        #elif UNITY_IPHONE
                    string dbpath = Application.dataPath + "/Raw/" + dbfilename;                                    log += "asset path is: " + dbpath;
                    try{
                        using (FileStream fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read)){
                            bytes = new byte[fs.Length];
                            fs.Read(bytes, 0, (int)fs.Length);
                        }
                    } catch (Exception e) {
                        log += "\nTest Fail with Exception " + e.ToString();
                        log += "\n";
                    }
        #elif UNITY_ANDROID
                    string dbpath = Application.streamingAssetsPath + "/" + dbfilename;                 log += "asset path is: " + dbpath;
                    WWW    www    = new WWW(dbpath);
                    Download(www);
                    bytes = www.bytes;
        #endif
                    if (bytes != null)
                    {
                        try{
                            //
                            //
                            // copy database to real file into cache folder
                            using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                            {
                                fs.Write(bytes, 0, bytes.Length);             log += "\nCopy database from streaminAssets to persistentDataPath: " + filename;
                            }

                            //
                            // initialize database
                            //
                            db.Open(filename);                               log += "\nDatabase created! filename: " + filename;

                            Test2(db, ref log);
                        } catch (Exception e) {
                            log += "\nTest Fail with Exception " + e.ToString();
                            log += "\n\n Did you copy test.db into StreamingAssets ?\n";
                        }
                    }
                }
                else
                {
                    // it mean we already download prebuild data base and store into persistantPath
                    // lest update, I will call Test

                    try{
                        //
                        // initialize database
                        //
                        db.Open(filename);                               log += "Database created! filename:" + filename;

                        Test(db, ref log);
                    } catch (Exception e) {
                        log += "\nTest Fail with Exception " + e.ToString();
                        log += "\n on WebPlayer it must give an exception, it's normal.";
                    }
                }
            }
#if ENCRYPTION
            //
            // ENCRYPTION
            //

            if (GUI.Button(new Rect(170, 170, 150, 70), "Run SQLite\nfor ENCRYPTION scenario"))
            {
                try {
                    db = new SQLiteDB();

                    log = "";

                    // a product persistant database path.
                    string filename = Application.persistentDataPath + "/demo_from_encryption.db";

                    File.Delete(filename);

                    db.Open(filename);


                    //
                    // set ENCRYPTION
                    //
                    SQLiteQuery qr = new SQLiteQuery(db, "PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
                    qr.Step();
                    qr.Release();

                    //
                    // create table
                    //
                    qr = new SQLiteQuery(db, queryCreate);
                    qr.Step();
                    qr.Release();                                        log += "\nTable created.";

                    //
                    // insert string and blob
                    //
                    qr = new SQLiteQuery(db, queryInsert);
                    qr.Bind(testString);
                    qr.Bind(testBlob);
                    qr.Step();
                    qr.Release();                                        log += "\nInsert test string and blob.";


                    // close
                    db.Close();

                    // and open again
                    db.Open(filename);

                    //
                    // set ENCRYPTION AGAIN, you could  try change to see ENCRYPTION works
                    //
                    qr = new SQLiteQuery(db, "PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";");
                    qr.Step();
                    qr.Release();

                    // do test
                    Test2(db, ref log);
                } catch (Exception e) {
                    log += "\nTest Fail with Exception " + e.ToString();
                    log += "\n on WebPlayer it must give an exception, it's normal.";
                }
            }
#endif
        }
        else
        {
            if (GUI.Button(new Rect(10, 10, 150, 50), "Back"))
            {
                db = null;
            }
            GUI.Label(new Rect(10, 70, 600, 600), log);
        }
    }
コード例 #44
0
ファイル: DemoObject.cs プロジェクト: led-os/unity_kidsgame
    void Test(SQLiteDB db, ref string log)
    {
        SQLiteQuery qr;


        //
        // delete table if exists
        //
        qr = new SQLiteQuery(db, queryDelete);
        qr.Step();
        qr.Release();                                        log += "\nTable deleted.";

        //
        // create table
        //
        qr = new SQLiteQuery(db, queryCreate);
        qr.Step();
        qr.Release();                                        log += "\nTable created.";

        //
        // insert string and blob
        //
        qr = new SQLiteQuery(db, queryInsert);
        qr.Bind(testString);
        qr.Bind(testBlob);
        qr.Step();
        qr.Release();                                        log += "\nInsert test string and blob.";

        //
        // read strings
        //
        string testStringFromSelect = "";

        qr = new SQLiteQuery(db, querySelect);
        while (qr.Step())
        {
            testStringFromSelect = qr.GetString("str_field");
            if (testStringFromSelect != testString)
            {
                throw new Exception("Test string are not equal!");
            }

            byte[] testBlobFromSelect = qr.GetBlob("blob_field");

            if (testBlobFromSelect.Length != testBlob.Length)
            {
                throw new Exception("Test blobs are not equal!");
            }

            for (int i = 0; i < testBlobFromSelect.Length; i++)
            {
                if (testBlobFromSelect[i] != testBlob[i])
                {
                    throw new Exception("Test blobs are not equal!");
                }
            }
        }
        if (testStringFromSelect == "")
        {
            throw new Exception("Unknowm problem!");
        }
        qr.Release();                                        log += "\nRead and test strings and blobs.";

        //
        //
        // delete table
        //
        qr = new SQLiteQuery(db, queryDelete);
        qr.Step();
        qr.Release();                                        log += "\nTable deleted.";

        //
        // if we reach that point it's mean we pass the test!
        db.Close();                                           log += "\nDatabase closed!\nTest succeeded!";
    }