火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Flex SQLite Batch Insert Datas from Array

Posted on 2010-07-27 08:19  剑廿三  阅读(645)  评论(0编辑  收藏  举报
        [Bindable(event="message")]
        
private function dbSyncData():void 
        { 
            
            stmt.addEventListener(SQLEvent.RESULT, dbExecuteBatchSQL);
            
            var dataArray:Array 
= this.params.SyncDataArray as Array;
            
            
if(dataArray == null){
                dispatchEvent(
new MessagesEvent("同步到 SQLite","失败:数据源记录集是空的。"));
                
return;
            }
            
            var dataTable:String 
= this.params.SyncDataTable as String;
            
            
if(dataTable == null){
                dispatchEvent(
new MessagesEvent("同步到 SQLite","失败:数据表名称未定义。"));
                
return;
            }
            
            dispatchEvent(
new MessagesEvent("同步到 SQLite","准备将 "+ dataArray.length +" 条记录同步到 "+ dataTable +" 数据表"));
            
            
this._execSQLBatch = new Array();
            
            
if(dataTable == "stockdaily"){
                
for(var i:int=0;i<dataArray.length;i++){
                    var o:Object 
= dataArray[i];
                    var sql:String 
= "INSERT INTO stockdaily (StatDate,Symbol,FinalPrice,HighPrice,LowPrice,DealVolume,DealMoney,RunDate) "+
                        
" VALUES ('@StatDate','@Symbol',@FinalPrice,@HighPrice,@LowPrice,@DealVolume,@DealMoney,'@RunDate')"
                        .replace(
"@StatDate", o["StatDate"])
                        .replace(
"@Symbol", o["Symbol"])
                        .replace(
"@FinalPrice", o["FinalPrice"])
                        .replace(
"@HighPrice", o["HighPrice"])
                        .replace(
"@LowPrice", o["LowPrice"])
                        .replace(
"@DealVolume", o["DealVolume"])
                        .replace(
"@DealMoney", o["DealMoney"])
                        .replace(
"@RunDate", o["RunDate"])
                        ;
                    
this._execSQLBatch.push(sql);
                }
            }
else if(dataTable == "stockdailywatch"){
                
for(var i:int=0;i<dataArray.length;i++){
                    var o:Object 
= dataArray[i];
                    var sql:String 
= "INSERT INTO stockdailywatch (Symbol,Name) VALUES ('@Symbol','@Name')"
                        .replace(
"@StatDate", o["StatDate"])
                        .replace(
"@Name", o["Name"])
                        ;
                    
this._execSQLBatch.push(sql);
                }
            }
            
            
this._execSQLCallLatency = this.dbSyncDataResult;
            
            
this.dbExecuteBatchSQL(null);
            
        }
        
        
private function dbSyncData():void 
        { 
            dispatchEvent(
new MessagesEvent("同步到 SQLite","同步数据完毕。"));
        }