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/>}