使用事务方式提交数据,如果上一条数据还在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数据库优化