bool SelectStepCallback(SQLiteQuery qr, bool hasdata, object state) { TestCallbackData data = state as TestCallbackData; if (hasdata) { // we have something to read! // do test readed values... string 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!"); } } data.Decriment(); } return(hasdata); // repeat, maybe we have one more record }
void SelectStepCallback(SQLiteQuery qr, bool step, object state) { TestCallbackData data = state as TestCallbackData; if (step) { // we have something to read! // do test readed values... string 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!"); } } data.Decriment(); // do next read. asyncDB.Step(qr, SelectStepCallback, state); } else { // we reach limit or finish reading. asyncDB.Release(qr, SelectQueryReleased, null); } }
void InsertQueryReleased(object state) { // well done, we just added one more row! // now check 1000 counter! TestCallbackData data = state as TestCallbackData; // increment counter data.Increment(); // check what to do next? if (data.Count < recordsNum) { // ok, add more please :) asyncDB.Query(queryInsert, InsertQueryCreated, data); } else { // we just added 1000 records, now read them! asyncDB.Query("SELECT * FROM test_values", SelectQueryCreated, data); } }
void OnGUI() { if (demoData == null) { if (GUI.Button(new Rect(10, 10, 150, 70), "Run asynchronous")) { // that just show how to pass an object to callback. demoData = new TestCallbackData(); // start from creation of 1000 records asyncDB.Query(queryInsert, InsertQueryCreated, demoData); } } // display frame count and records count - to show that game don't stop while we reading or writing. string log = "Please, press the button to run test."; if (demoData != null) { log = "Frame: " + frameCount + ", Record Count: " + demoData.Count; } GUI.Label(new Rect(10, 80, 600, 600), log); }
void SelectQueryReleased(object state) { // finish demoData = null; }
void OnGUI() { if( demoData == null ) { if ( GUI.Button(new Rect (10,10,150,70), "Run asynchronous") ) { // that just show how to pass an object to callback. demoData = new TestCallbackData(); // start from creation of 1000 records asyncDB.Query(queryInsert, InsertQueryCreated, demoData); } } // display frame count and records count - to show that game don't stop while we reading or writing. string log = "Please, press the button to run test."; if( demoData != null ) { log = "Frame: " + frameCount + ", Record Count: " + demoData.Count; } GUI.Label (new Rect (10,80,600,600), log); }