<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Li Guoliang &#187; SQLite</title>
	<atom:link href="http://liguoliang.com/tag/sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>http://liguoliang.com</link>
	<description>ActionScript Flex Java JEE PHP...</description>
	<lastBuildDate>Mon, 21 May 2012 17:04:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>[Tips]Flex中取得SQLite的最后插入记录的ID SELECT last_insert_rowid()</title>
		<link>http://liguoliang.com/2008/tipsflex%e4%b8%ad%e5%8f%96%e5%be%97sqlite%e7%9a%84%e6%9c%80%e5%90%8e%e6%8f%92%e5%85%a5%e8%ae%b0%e5%bd%95%e7%9a%84id-select-last_insert_rowid/</link>
		<comments>http://liguoliang.com/2008/tipsflex%e4%b8%ad%e5%8f%96%e5%be%97sqlite%e7%9a%84%e6%9c%80%e5%90%8e%e6%8f%92%e5%85%a5%e8%ae%b0%e5%bd%95%e7%9a%84id-select-last_insert_rowid/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 15:16:00 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/10/142/</guid>
		<description><![CDATA[<p></p><p class='read-more'><a href='http://liguoliang.com/2008/tipsflex%e4%b8%ad%e5%8f%96%e5%be%97sqlite%e7%9a%84%e6%9c%80%e5%90%8e%e6%8f%92%e5%85%a5%e8%ae%b0%e5%bd%95%e7%9a%84id-select-last_insert_rowid/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p><span id="more-142"></span>
<p>在Insert之后,使用SELECT last_insert_rowid()可直接得到最后一次插入的记录的id</p>
<p>如果之前没有进行任何Insert的操作,则返回0;</p>
<p>使用方法:</p>
<pre class="java" name="code">//插入成功后的响应, 同时运行SQL语句, 以获得其ID;
private function onInsertCatSuccess(e:SQLEvent):void {
    //该语句用来执行SELECT last_insert_rowid()
     //AppContext.getInstance().dbConn为数据库连接,Statements.getLastInserRowID为SELECT last_insert_rowid(),null为sql语句参数,后面两个函数分别为成功与失败的响应
    SQLUtils.createAndExecuteStatement(AppContext.getInstance().dbConn, Statements.getLastInserRowID, null, onGetCatIDSuccess, onGetCatIDFail);
} </pre>
<p>下面是成功拿到id后的响应函数: </p>
<pre class="java" name="code">		//获得ID后, 新建CAt对象,加入到上级目录...
		private function onGetCatIDSuccess(e:SQLEvent):void {
			var result:SQLResult = e.target.getResult();
			catToBeAdded.id = result.data[0][&quot;last_insert_rowid()&quot;];
			LogUtils.catLog.info(&quot;获得ID为: &quot; + catToBeAdded.id);
		}</pre>
<p>其中result.data[0][&quot;last_insert_rowid()&quot;]便是lastinse_rowid;</p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/tipsflex%e4%b8%ad%e5%8f%96%e5%be%97sqlite%e7%9a%84%e6%9c%80%e5%90%8e%e6%8f%92%e5%85%a5%e8%ae%b0%e5%bd%95%e7%9a%84id-select-last_insert_rowid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AIR中使用SQLite新手入门</title>
		<link>http://liguoliang.com/2008/air%e4%b8%ad%e4%bd%bf%e7%94%a8sqlite%e6%96%b0%e6%89%8b%e5%85%a5%e9%97%a8/</link>
		<comments>http://liguoliang.com/2008/air%e4%b8%ad%e4%bd%bf%e7%94%a8sqlite%e6%96%b0%e6%89%8b%e5%85%a5%e9%97%a8/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 02:24:00 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/09/88/</guid>
		<description><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<p>关于SQLite的介绍: <a title="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/" href="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/">http://www.ibm.com/developerworks/cn/opensource/os-sqlite/</a></p>
<h2>1. 确定连接模式</h2>
<p>首先要确定连接模式, 是asynchronous[异步], 还是synchronous[同步].</p>
<p>异步执行方式: 运行操作数据库的指令, 数据库在后台运行, 在操作结束或失败后会dispatch一个Event,由该Event激发后续代码继续运行.异步方式有一个明显的好处: 数据库的操作是在后台运行的, 而与此同时,你的主程序代码可同时运行. 更为重要的是, 你不能因为数据库操作没有结束而冻结用户窗口.</p>
<p>从概念上来讲, 使用同步方式要比异步方式简单一些, 因为同步方式的代码可以按照一个次序进行, 而异步方式主要通过EventListener.</p>
<p>同步执行方式: 除了异步执行方式之外, Adobe AIR 也支持同步方式, 但是对数据库的操作不在后台运行, 而是使用与主程序同一个线程.</p>
<p></p><p class='read-more'><a href='http://liguoliang.com/2008/air%e4%b8%ad%e4%bd%bf%e7%94%a8sqlite%e6%96%b0%e6%89%8b%e5%85%a5%e9%97%a8/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<p>关于SQLite的介绍: <a title="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/" href="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/">http://www.ibm.com/developerworks/cn/opensource/os-sqlite/</a></p>
<h2>1. 确定连接模式</h2>
<p>首先要确定连接模式, 是asynchronous[异步], 还是synchronous[同步].</p>
<p>异步执行方式: 运行操作数据库的指令, 数据库在后台运行, 在操作结束或失败后会dispatch一个Event,由该Event激发后续代码继续运行.异步方式有一个明显的好处: 数据库的操作是在后台运行的, 而与此同时,你的主程序代码可同时运行. 更为重要的是, 你不能因为数据库操作没有结束而冻结用户窗口.</p>
<p>从概念上来讲, 使用同步方式要比异步方式简单一些, 因为同步方式的代码可以按照一个次序进行, 而异步方式主要通过EventListener.</p>
<p>同步执行方式: 除了异步执行方式之外, Adobe AIR 也支持同步方式, 但是对数据库的操作不在后台运行, 而是使用与主程序同一个线程.</p>
<p><span id="more-88"></span></p>
<p>每种连接方式都各有所长, 下面以asynchronous方式讲述AIR中使用AS对SQLite进行操作:</p>
<h2>2. 具体代码:</h2>
<p>1.连接数据库:</p>
<pre class="java" name="code">   1. /**
   2.  * 建立一个只读连接.以检测数据库连接是否正常.
   3.  * openAsync的openmodel参数默认为creat,即:如果不指定具体openmodel的话,
即使没有数据库,也会建立.
   4.  */
   5. private function init():void {
   6.     connReadOnly.addEventListener(SQLEvent.OPEN,connToDBSuccess);
   7.     connReadOnly.addEventListener(SQLErrorEvent.ERROR,connToDBFail);
   8.     connReadOnly.openAsync(Connection.dbFile,SQLMode.READ);
   9. }
  10.
  11. /**
  12.  * 数据库存在并连接成功的响应函数
  13.  */
  14. private function connToDBSuccess(event:SQLEvent):void {
  15.     LogUtils.defaultLog.info("DataBase Connected");
  16. }
  17.
  18. /**
  19.  * 在数据库连接出错时运行
  20.  */
  21. private function connToDBFail(event:SQLErrorEvent):void {
  22.     LogUtils.defaultLog.fatal(event.error.message);
  23. }</pre>
<p>待续……</p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/air%e4%b8%ad%e4%bd%bf%e7%94%a8sqlite%e6%96%b0%e6%89%8b%e5%85%a5%e9%97%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用Air与SQLite开发NoteManagement</title>
		<link>http://liguoliang.com/2008/%e4%bd%bf%e7%94%a8air%e4%b8%8esqlite%e5%bc%80%e5%8f%91notemanagement/</link>
		<comments>http://liguoliang.com/2008/%e4%bd%bf%e7%94%a8air%e4%b8%8esqlite%e5%bc%80%e5%8f%91notemanagement/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 09:33:22 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2008/09/69/</guid>
		<description><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<h2>1. 设计目标:</h2>
<p><a href="http://liguoliang.com/wp-content/uploads/2008/09/png0808.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin-left: 0px; margin-right: 0px; border-right-width: 0px" title="png-0808" src="http://liguoliang.com/wp-content/uploads/2008/09/png0808-thumb.png" border="0" alt="png-0808" width="128" height="128" align="right" /></a></p>
<p><a href="http://liguoliang.com/wp-content/uploads/2008/09/png0808.png"></a></p>
<p>设计NoteManagement 的Air 版,使用SQLite数据,实现之前所有的功能,如:用户注册登录,目录及便条的增加删除修改等.<a href="http://www.riashanghai.com/node/27" target="_blank">[点此查看NoteManagement的WEB版]</a>.</p>
<h3>2. 概要设计:</h3>
<p>相对于前述WEB 版,Air 版的数据源已不再是ShareObject或XML,所以需要通过对数据库的存取进行操作.<br />
另外,考虑到性能,对于Tree 进行Dynamic Loading, 以优化性能.</p>
<p></p><p class='read-more'><a href='http://liguoliang.com/2008/%e4%bd%bf%e7%94%a8air%e4%b8%8esqlite%e5%bc%80%e5%8f%91notemanagement/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<h2>1. 设计目标:</h2>
<p><a href="http://liguoliang.com/wp-content/uploads/2008/09/png0808.png"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin-left: 0px; margin-right: 0px; border-right-width: 0px" title="png-0808" src="http://liguoliang.com/wp-content/uploads/2008/09/png0808-thumb.png" border="0" alt="png-0808" width="128" height="128" align="right" /></a></p>
<p><a href="http://liguoliang.com/wp-content/uploads/2008/09/png0808.png"></a></p>
<p>设计NoteManagement 的Air 版,使用SQLite数据,实现之前所有的功能,如:用户注册登录,目录及便条的增加删除修改等.<a href="http://www.riashanghai.com/node/27" target="_blank">[点此查看NoteManagement的WEB版]</a>.</p>
<h3>2. 概要设计:</h3>
<p>相对于前述WEB 版,Air 版的数据源已不再是ShareObject或XML,所以需要通过对数据库的存取进行操作.<br />
另外,考虑到性能,对于Tree 进行Dynamic Loading, 以优化性能.</p>
<p><span id="more-69"></span></p>
<p><!--break--></p>
<h3>3. 具体实现:</h3>
<p>3.1 程序与数据库之间的操作:<br />
3.1.1 与据库建立连接:</p>
<pre class="java" name="code">
/**
	 * 建立一个只读连接.以检测数据库连接是否正常.
	 * openAsync的openmodel参数默认为creat,即:如果不指定具体openmodel的话,即使没有数据库,也会建立.
	 */
	private function init():void {
		connReadOnly.addEventListener(SQLEvent.OPEN,connToDBSuccess);
		connReadOnly.addEventListener(SQLErrorEvent.ERROR,connToDBFail);
		connReadOnly.openAsync(Connection.dbFile,SQLMode.READ);
	}

	/**
	 * 数据库存在并连接成功的响应函数
	 */
	private function connToDBSuccess(event:SQLEvent):void {
		LogUtils.defaultLog.info("DataBase Connected");
	}

	/**
	 * 在数据库连接出错时运行
	 */
	private function connToDBFail(event:SQLErrorEvent):void {
		LogUtils.defaultLog.fatal(event.error.message);
	}
</pre>
<h3>3.1.2 数据操作:</h3>
<p>以目录删除举例:</p>
<p>/**</p>
<p>* 删除Cat</p>
<pre class="java">		/**
		 * 删除Cat
		 */
		private function delCat():void {
			var sql:String =
			"DELETE FROM Cat WHERE cat_ID = " + selectedCat.id;
			SQLUtils.createAndExecuteStatement(conn, sql, null, delCatInDBSuccess);
		}

		private function delCatInDBSuccess(e:SQLEvent):void {
			LogUtils.defaultLog.info("目录: " + selectedCat.label + " 已从数据库删除");
			var i:int = selectedCat.parent.subCats.getItemIndex(selectedCat);
			selectedCat.parent.subCats.removeItemAt(i);
			TipsUtils.tipsPrint(tipsLabel,"Cat: " + selectedCat.label + " has been Deleted Success");
		}</pre>
<p>其中的SQLUtils.createAndExecuteStatement是一个Static的函数,具体代码如下:</p>
<p>/**<br />
* 该函数可执行指定的sql语句,并添加事件监听<br />
* 参数说明:<br />
* conn: 与数据库的连接, sql: 需要执行的SQL语句,<br />
* Parameters: sql语句如果需要参数,则由其提供,如insert 语句.默认为空<br />
* onSuccess: sql语句执行成功的响应函数.<br />
* onFail: sql语句执行失败的响应函数,如果不指定则会自动增加一个通用的ErrorHandler;<br />
*/<br />
public static function createAndExecuteStatement(conn:SQLConnection, sql:String, parameters:Array=null, onSuccess:Function=null, onFail:Function=null):SQLStatement {<br />
var executeStatement:SQLStatement = new SQLStatement();<br />
executeStatement.sqlConnection = conn;<br />
executeStatement.text = sql;<br />
if(parameters!=null) {<br />
for(var i:int=0; i</p>
<p>executeStatement.parameters[i] = parameters[i];<br />
}<br />
}<br />
if(onSuccess != null) {<br />
executeStatement.addEventListener(SQLEvent.RESULT,onSuccess);<br />
}<br />
if(onFail != null) {<br />
executeStatement.addEventListener(SQLErrorEvent.ERROR, onFail);<br />
} else {<br />
executeStatement.addEventListener(SQLErrorEvent.ERROR, commonErrorHandler)<br />
}</p>
<p>executeStatement.execute();<br />
LogUtils.defaultLog.info(&#8220;SQL: &#8221; + sql);<br />
return executeStatement;<br />
}</p>
<p>public static function commonErrorHandler(e:SQLErrorEvent):void {<br />
LogUtils.defaultLog.warn(&#8220;Common Error: &#8221; + e.toString());<br />
}</p>
<h4>4.相关知识点总结:</h4>
<p>4.1 SQLite简介:<a title="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/" href="http://www.ibm.com/developerworks/cn/opensource/os-sqlite/">http://www.ibm.com/developerworks/cn/opensource/os-sqlite/</a></p>
<p>4.2 SQLite管理工具:<a title="https://addons.mozilla.org/en-US/firefox/addon/5817" href="https://addons.mozilla.org/en-US/firefox/addon/5817">https://addons.mozilla.org/en-US/firefox/addon/5817</a></p>
<p>4.3 基本SQL语法:<a title="http://w3school.com.cn/sql/index.asp" href="http://w3school.com.cn/sql/index.asp">http://w3school.com.cn/sql/index.asp</a></p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/%e4%bd%bf%e7%94%a8air%e4%b8%8esqlite%e5%bc%80%e5%8f%91notemanagement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

