zoukankan      html  css  js  c++  java
  • AIR for androd 笔记

     1 1.stage.addEventListener(Event.ACTIVE,onActive);
     2 
     3   stage.addEventListener(Event.DEACTIVE,onDeactive);
     4 
     5 
     6 
     7 2.KeyboardEvent
     8    switch(e.keycode){
     9         case Keyboard.BACK:  break;
    10         case Keyboard.HOME: break;
    11         case Keyboard.SEARCH: break;
    12     }
    13 }


    SQLite是运行本地环境的一个数据库系统,保存数据在硬盘上的文件中。每一个数据库保存一个文件

    首先创建一个数据库,然后打开数据库(这两部可以一起),创建表,

    创建db:

     1 import flash.filesystem.File;
     2 import flash.events.SQLErrorEvent;
     3 import flash.events.SQLEvent;
     4 import flash.data.SQLConnection;
     5 
     6 var file:File=File.applicationStorageDirectory.resolvePath("test.db");
     7 var conn:SQLConnection=new SQLConnection();
     8 conn.addEventListener(SQLEvent.OPEN,onOpen);
     9 conn.addEventListener(SQLErrorEvent.ERROR,onError);
    10 try{
    11     conn.open(file);
    12     txt.appendText("-----open ");
    13 }catch(e){
    14     txt.appendText("-----error oh!!!");
    15 }
    16 function onOpen(e:SQLEvent){
    17     txt.appendText("-----open success");
    18 }
    19 function onError(e:SQLErrorEvent){
    20     txt.appendText("-----open error");
    21 }

     创建表:

     1 var sql:String ="CREATE TABLE IF NOT EXISTS employees (" +  
     2     "    empId INTEGER PRIMARY KEY AUTOINCREMENT, " +  
     3     "    firstName TEXT, " +  
     4     "    lastName TEXT, " +  
     5     "    salary NUMERIC CHECK (salary > 0)" +  
     6     ")"; 
     7 var statm:SQLStatement=new SQLStatement();
     8 statm.addEventListener(SQLEvent.RESULT,onResult);
     9 statm.sqlConnection=conn;
    10 statm.text=sql;
    11 statm.execute();
    12 function onResult(e:SQLEvent){
    13     trace("----创建表成功");
    14 }

    查询数据:

     1 selectStmt.sqlConnection = conn; 
     2      
     3 selectStmt.text = "SELECT itemId, itemName, price FROM products"; 
     4      
     5 selectStmt.addEventListener(SQLEvent.RESULT, resultHandler); 
     6 selectStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); 
     7      
     8 selectStmt.execute(); 
     9      
    10 function resultHandler(event:SQLEvent):void 
    11 { 
    12     var result:SQLResult = selectStmt.getResult(); 
    13      
    14     var numResults:int = result.data.length; 
    15     for (var i:int = 0; i < numResults; i++) 
    16     { 
    17         var row:Object = result.data[i]; 
    18         var output:String = "itemId: " + row.itemId; 
    19         output += "; itemName: " + row.itemName; 
    20         output += "; price: " + row.price; 
    21         trace(output); 
    22     } 
    23 } 
    24      
    25 function errorHandler(event:SQLErrorEvent):void 
    26 { 
    27     // Information about the error is available in the 
    28     // event.error property, which is an instance of  
    29     // the SQLError class. 
    30 }

    插入数据:

     1 var insertStmt:SQLStatement = new SQLStatement(); 
     2 insertStmt.sqlConnection = conn; 
     3      
     4 // define the SQL text 
     5 var sql:String =  
     6     "INSERT INTO employees (firstName, lastName, salary) " +  
     7     "VALUES ('Bob', 'Smith', 8000)"; 
     8 insertStmt.text = sql; 
     9      
    10 // register listeners for the result and failure (status) events 
    11 insertStmt.addEventListener(SQLEvent.RESULT, insertResult); 
    12 insertStmt.addEventListener(SQLErrorEvent.ERROR, insertError); 
    13      
    14 // execute the statement 
    15 insertStmt.execute(); 
    16      
    17 function insertResult(event:SQLEvent):void 
    18 { 
    19     trace("INSERT statement succeeded"); 
    20 } 
    21      
    22 function insertError(event:SQLErrorEvent):void 
    23 { 
    24     trace("Error message:", event.error.message); 
    25     trace("Details:", event.error.details); 
    26 } 

     使用加密的数据库

  • 相关阅读:
    121. Best Time to Buy and Sell Stock
    70. Climbing Stairs
    647. Palindromic Substrings
    609. Find Duplicate File in System
    583. Delete Operation for Two Strings
    556 Next Greater Element III
    553. Optimal Division
    539. Minimum Time Difference
    537. Complex Number Multiplication
    227. Basic Calculator II
  • 原文地址:https://www.cnblogs.com/1000pen/p/2817006.html
Copyright © 2011-2022 走看看