Flex-enable SQLite to create only one connection

Source: Internet
Author: User
ArticleDirectory
    • Problem
    • Solution
    • Detailed description
    • Code

 

Problem

When the air application is executedProgramIn this case, we connect to the database file and create the same table.

Solution

To solve this problem, verify whether the SQLite command if not exists is used when the table is created to the database file.

 

 

 

 

Detailed description

 

One way to solve this problem is as follows:Code. The first function only connects to database. dB, and the second function creates a table in the database file. We usually create a table without verifying whether the table has been created to the file database. DB. We only use the create table command of SQLite, but it always creates a table when running the application. We can solve this problem by using if not exists.

 

 

 

Code

Private function Init (): void <br/>{< br/> conn = new sqlconnection (); <br/> try <br/>{< br/> var dbfile: file = file. applicationstoragedirectory. resolvepath ("database. DB "); <br/> Conn. open (dbfile); <br/>}< br/> catch (error: sqlerror) <br/>{< br/> trace ("error Opening Database "); <br/> trace ("error. message: ", error. message); <br/> trace ("error. details: ", error. details); <br/> return; <br/>}< br/> createtable (); <br/>}</P> <p> private function createtable (): void <br/>{< br/> createstmt = new sqlstatement (); <br/> createstmt. sqlconnection = conn; <br/> var SQL: String = ""; <br/> SQL + = "CREATE TABLE if not exists rssurl ("; <br/> SQL + = "idinteger primary key autoincrement,"; <br/> SQL + = "postnametext,"; <br/> SQL + = "posturltext ,"; <br/> SQL + = "posttexttext"; <br/> SQL + = ")"; <br/> createstmt. TEXT = SQL; </P> <p> try <br/>{< br/> createstmt.exe cute (); <br/>}< br/> catch (error: sqlerror) <br/>{< br/> trace ("error creating table"); <br/> trace ("create table error:", error ); <br/> trace ("error. message: ", error. message); <br/> trace ("error. details: ", error. details); <br/> return; <br/>}< br/>}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.