c# - how to resolve this sqlite exception constraint -


i making flight data app on windows store apps. app track flights departing & arriving in pakistan.

i'm getting data via json

https://developer.flightstats.com/

and saving sqlite database.

this function getting data

p.s: variables used in connection string declared , assigned irrelevant i'm not showing them.

public async void getdata() {     var dbpath = path.combine(windows.storage.applicationdata.current.localfolder.path, "flight_record.sqlite");      (int hour = 0; hour < 24; hour++)     {         httpclient web = new httpclient();         var response = await web.getstringasync("https://api.flightstats.com/flex/flightstatus/rest/v2/json/airport/status/khi/arr/" + year + "/" + month + "/" + today + "/" + hour + "?appid=" + appid + "&appkey=" + appkey + "&utc=false&numhours=1&maxflights=10");          jsondata1 data1 = jsonconvert.deserializeobject<jsondata1>(response);          (int = 0; < data1.flightstatuses.length; i++)         {             int f_id = convert.toint32(data1.flightstatuses[i].flightid);             string l_time = data1.flightstatuses[i].arrivaldate.datelocal.timeofday.tostring();             string year1 = data1.flightstatuses[i].arrivaldate.datelocal.year.tostring();             string month1 = data1.flightstatuses[i].arrivaldate.datelocal.month.tostring();             string day1 = data1.flightstatuses[i].arrivaldate.datelocal.day.tostring();             string departureairport1 = data1.flightstatuses[i].departureairportfscode.tostring();             string arrivalairport1 = data1.flightstatuses[i].arrivalairportfscode.tostring();             string stats = data1.flightstatuses[i].status.tostring();             string fscode = data1.flightstatuses[i].carrierfscode.tostring();             string flightnumber1 = data1.flightstatuses[i].flightnumber.tostring();              //here arival_data sqlite database table              using (var db = new sqlite.sqliteconnection(dbpath))             {                 db.execute("insert arrival_data (flightid, time, year, month, day, departureairport, arrivalairport, status, airline, carrierfscode, flightnumber) values ('" + f_id + "', '" + l_time + "', '" + year1 + "', '" + month1 + "', '" + day1 +                     "', '" + departureairport1 + "', '" + arrivalairport1 + "', '" + stats + "', '" + airline1 +                     "', '" + fscode + "', '" + flightnumber1 + "')");             }         }     } } 

my request query supports 1 query per hour, have made loop run 23 times.

every hour number of flights different i've used data1.flightstatuses.length in second loop.

after i'm inserting data table.

when run app following exception

enter image description here

i did debugging , instead of inserting data db, i'm displaying in listbox , found result

enter image description here

if @ result, time not in incrementing order. hence exception!

so how organize data time in incrementing order, or there way?

several causes possible, order in insert data not 1 of them.

let's take closer @ sample data, 1st & 4th row, duplicates! makes me think unique constraint being violated.

first thing @ primary key on table. flightid?

you'll need have think want multiple rows same flight. may want way of efficiently updating data when exists or inserting if not, known upsert, see q&a here.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -