使用Flex从SQLite数据库实现“Next”或“Prev”按钮

时间:2011-08-09 00:05:45

标签: flex sqlite

我试图让我的本地sqlite数据库在点击按钮时显示下一条记录。

我查看了Getting next record in SQLite database for mobile application这样的帖子,但他们的代码对我来说几乎没有提供解决方案。以下是我的代码示例:

AS3:

    private function getNext():void
        {
            nextRecordId = targetRecordId + 1;

            selectStmt = new SQLStatement();
            selectStmt.sqlConnection = conn;
            var sql:String = "SELECT [Index], Title, CAST(Picture AS ByteArray) AS Picture FROM Data WHERE [Index] = 1" ;
            /*  selectStmt.parameters[@nextRecordId] = nextRecordId;  */ // Id of next record
            selectStmt.text = sql;
            selectStmt.addEventListener(SQLEvent.RESULT, selectResult2);
            selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError2);
            selectStmt.execute();

        }

        private function selectResult2(event:SQLEvent):void
        {
            selectStmt.removeEventListener(SQLEvent.RESULT, selectResult2);
            selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError2);

            var result2:SQLResult = selectStmt.getResult(); 

            dataField2 = new ArrayCollection(result2.data);
            dp2 = ArrayCollection(dataField);  

            if (result2.data != null) 
            {
                pngIndex = result2.data[0].Index;
                pngTitle = result2.data[0].Title;
                pngByteArray = result2.data[0].Picture; 
                displayPic.source = pngByteArray;
            }   
        }

UI MXML:

    <s:Scroller interactionMode="touch"
            width="640"
            height="830">   
        <s:Group>
            <s:Image id="displayPic"
                     x="0" y="16" 
                     width="640" 
                     scaleMode="stretch" 
                     smooth="true" smoothingQuality="high"
                     />
            <!--<s:TextArea x="9" y="731" text="@{pngTitle}"/>-->
    </s:Group>
</s:Scroller>

非常感谢帮助/建议

1 个答案:

答案 0 :(得分:0)

我没看到你遇到问题的地方。你试过这个名为谷歌的东西吗?

selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
selectStmt.text = "SELECT Title, CAST(Picture AS ByteArray) AS Picture FROM Data WHERE id=@index LIMIT 1";
selectStmt.parameters['@index'] = index++;
selectStmt.execute();

只要将该索引变量保持为默认设置为0的类var,就应该没问题,直到行用完为止。当然,还有其他方法可以做到这一点,比如获取所有行的数组并让actionscript管理它。如果您没有非常大的信息数据库,这将更容易。