• 【设为首页】
  • 【收藏闪客居】
当前位置:主页 > AIR > 文章内容
  • AIR中批量insert数据应该怎么解决?

  • 来源:moorwind.com 作者:kono 2008-09-22 【 】 TAG:

使用事务方式提交数据,如果上一条数据还在executing,那么下一条数据提交就会抛异常。

public function InsertArray(value:Array):void
{
  var i:int;
  var sql:String = "INSERT INTO blog (blogSourceId, tittle, authors, link, pubDate, guid, description)";
  sql += "VALUES(@blogSourceId, @tittle, @authors, @link, @pubDate, @guid, @description)";
  
  this._insertBlogItemAState = new SQLStatement();
  this._insertBlogItemAState.sqlConnection = this._connection;
  this._insertBlogItemAState.text = sql;
  this._insertBlogItemAState.addEventListener(SQLEvent.RESULT, onBlogItemChangeResult_handler);
  this._insertBlogItemAState.addEventListener(SQLErrorEvent.ERROR, onBlogItemChangeError_handler);
  
  this._connection.begin();
  for(i = 0; i < value.length; i++)
  {
    var bs:BlogItemVO = value[i];
    
    this._insertBlogItemAState.parameters["@blogSourceId"] = bs.blogSourceId;
    this._insertBlogItemAState.parameters["@tittle"] = bs.title;
    this._insertBlogItemAState.parameters["@authors"] = bs.authors;
    this._insertBlogItemAState.parameters["@link"] = bs.link;
    this._insertBlogItemAState.parameters["@pubDate"] = bs.pubDate;
    this._insertBlogItemAState.parameters["@guid"] = bs.guid;
    this._insertBlogItemAState.parameters["@description"] = bs.description;
    
    _insertBlogItemAState.execute();
    
      
  }
  try
  {
    this._connection.commit();  
  }
  catch(e:SQLError)
  {
    trace(e);
  }
      
  
}


那么换一种写法,但是,速度降下来了...

public function InsertArray(value:Array):void
{
  var i:int;
  var sql:String = "INSERT INTO blog (blogSourceId, tittle, authors, link, pubDate, guid, description)";
  sql += "VALUES(@blogSourceId, @tittle, @authors, @link, @pubDate, @guid, @description)";
  
  this._connection.begin();
  for(i = 0; i < value.length; i++)
  {
    this._insertBlogItemAState = new SQLStatement();
    this._insertBlogItemAState.sqlConnection = this._connection;
    this._insertBlogItemAState.text = sql;
    
    var bs:BlogItemVO = value[i];
    
    this._insertBlogItemAState.parameters["@blogSourceId"] = bs.blogSourceId;
    this._insertBlogItemAState.parameters["@tittle"] = bs.title;
    this._insertBlogItemAState.parameters["@authors"] = bs.authors;
    this._insertBlogItemAState.parameters["@link"] = bs.link;
    this._insertBlogItemAState.parameters["@pubDate"] = bs.pubDate;
    this._insertBlogItemAState.parameters["@guid"] = bs.guid;
    this._insertBlogItemAState.parameters["@description"] = bs.description;
    
    _insertBlogItemAState.execute();
    
      
  }
  try
  {
    this._connection.commit();  
  }
  catch(e:SQLError)
  {
    trace(e);
  }
}



上一篇:AIR结合FCKeditor实现图文混排   下一篇:Air支持SQLLite数据库优化
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)