I'm using flex to develop my first desktop app and I'm working with sqlite for the first time as well.
I'm creating my database and all the tables just fine, but I would also like to add a few rows of data into a couple of the tables so the inf开发者_如何学Cormation is present on first install.
The only problem I'm having is every time I run the program it keeps inserting the same data over and over again.
here's what I'm trying, but it doesn't seem to be working.
stmt.text = "CREATE TABLE IF NOT EXISTS tbl_breed ("+" breed_id INTEGER PRIMARY KEY AUTOINCREMENT, "+" breed_breed TEXT)";
stmt.execute();
stmt.text = "INSERT OR IGNORE INTO tbl_breed (breed_breed)"+" VALUES ('Test')";
stmt.execute();
thanks!
Ok so i figured it out... I guess you have to hard code the the primary key id value.
here what I had to do.
stmt.text = "CREATE TABLE IF NOT EXISTS tbl_breed ("+" breed_id INTEGER PRIMARY KEY AUTOINCREMENT, "+" breed_breed TEXT)";
stmt.execute();
stmt.text = "INSERT OR IGNORE INTO tbl_breed (breed_id,breed_breed)"+" VALUES ('1','test')";
stmt.execute();
you may also want to use parameter with queries. like
stmt.text = "insert into Mobile_gps_photo_data (GPS_LAT,GPS_LON,_PHOTO) values (:B,:C)";
stmt.parameters[":B"]=B;
stmt.parameters[":C"]=C;
stmt.execute();
精彩评论