Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import flash.desktop.NativeApplication;
- import flash.events.Event;
- import flash.events.InvokeEvent;
- import flash.system.Capabilities;
- import flash.filesystem.File;
- import flash.filesystem.FileStream;
- import flash.filesystem.FileMode;
- import flash.utils.*;
- import mx.utils.ObjectUtil;
- import qnx.ui.text.Label;
- [SWF(width="1024", height="600", backgroundColor="#cccccc")]
- public class SQLTest2 extends Sprite
- {
- public var label:Label;
- public function SQLTest2()
- {
- label = new Label();
- label.multiline = true;
- label.width = stage.stageWidth;
- label.height = stage.stageHeight;
- label.wordWrap = true;
- label.text = "this will be replaced";
- addChild(label);
- stage.nativeWindow.visible = true;
- import flash.data.SQLConnection;
- import flash.data.SQLStatement;
- import flash.errors.SQLError;
- import flash.data.SQLResult;
- import flash.filesystem.File;
- var imagePath:File = File.userDirectory.resolvePath('shared/camera/IMG_00000338.jpg');
- var dbpath:File = File.applicationStorageDirectory.resolvePath('my.db');
- dbpath.deleteFile();
- var times:Array = [];
- var conn:SQLConnection = new SQLConnection();
- try
- {
- conn.open(dbpath);
- times.push(getTimer()); // [0] 1533
- var stmt:SQLStatement = new SQLStatement();
- stmt.sqlConnection = conn;
- stmt.text = "CREATE TABLE IF NOT EXISTS test(foo TEXT PRIMARY KEY, bar BLOB)";
- stmt.execute();
- trace("executed", stmt.text);
- times.push(getTimer()); // [1] 366 ms
- var blob:ByteArray = new ByteArray();
- var imageFile:FileStream = new FileStream();
- imageFile.open(imagePath, FileMode.READ);
- imageFile.readBytes(blob);
- times.push(getTimer()); // [2] 152 ms
- trace('len1', blob.length);
- conn.begin();
- stmt.text = "INSERT INTO test VALUES (:foo, :bar)";
- stmt.parameters[':foo'] = 'client';
- stmt.parameters[':bar'] = blob;
- stmt.execute();
- trace("executed", stmt.text);
- times.push(getTimer()); // [3] 474 ms
- conn.commit();
- times.push(getTimer()); // [4] 3636 ms
- stmt.text = "SELECT foo, bar, length(bar) as len FROM test";
- stmt.clearParameters();
- stmt.execute();
- trace("executed", stmt.text);
- var result:SQLResult = stmt.getResult();
- label.text = String(result.data[0].foo);
- blob = result.data[0].bar;
- trace("results", result.data.length, result.data[0].len, blob.length);
- times.push(getTimer()); // [5] 282 ms
- conn.close();
- imagePath = File.applicationStorageDirectory.resolvePath('written.jpg');
- imagePath.deleteFile();
- imageFile.open(imagePath, FileMode.WRITE);
- imageFile.writeBytes(blob);
- imageFile.close()
- times.push(getTimer()); // [6] 36 ms
- }
- catch (error:SQLError)
- {
- trace("Error message:", error.message);
- trace("Details:", error.details);
- }
- trace('times', ObjectUtil.toString(times));
- var time:uint = times[0];
- for (var i:int = 1; i < times.length; i++) {
- trace(i, times[i] - time);
- time = times[i];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement