/// <summary> /// Writes the complete db into the sqlite table /// NOTE: Closes and releases SqLite DB items /// </summary> /// <param name="idb">The Icao Database as Input</param> /// <returns>String as result either empty or error</returns> public string LoadDBfromIcao(icaoDatabase idb) { string ret = icaoSqlWriter.WriteSqDB(idb, m_dbc); m_dbc.Close( ); m_dbc.Dispose( ); return(ret); }
/// <summary> /// Read the BS Aircraft table data into the IcaoDB provided /// NOTE: Closes and releases SqLite DB items /// </summary> /// <param name="idb">An ICAO db to fill</param> /// <returns>Result string either empty or error information</returns> public string ReadDb(ref icaoDatabase idb) { string ret = ""; if (m_dbc?.State == System.Data.ConnectionState.Open) { using (SQLiteCommand sqlite_cmd = m_dbc.CreateCommand( )) { sqlite_cmd.CommandText = "SELECT * FROM Aircraft"; using (SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader( )) { // The SQLiteDataReader allows us to run through each row per loop while (sqlite_datareader.Read( )) // Read() returns true if there is still a result line to read { /* Table aircraft: * 0 1 2 3 4 5 6 7 8 9 10 * "AircraftID", "FirstCreated", "LastModified", "ModeS", "ModeSCountry", "Country", "Registration", "CurrentRegDate", "PreviousID", "FirstRegDate", "Status", * 11 12 13 14 15 16 17 18 19 20 * "DeRegDate", "Manufacturer", "ICAOTypeCode", "Type", "SerialNo", "PopularName", "GenericName", "AircraftClass", "Engines", "OwnershipStatus", * 21 22 23 24 25 26 27 28 29 30 31 * "RegisteredOwners", "MTOW", "TotalHours", "YearBuilt", "CofACategory", "CofAExpiry", "UserNotes", "Interested", "UserTag", "InfoURL", "PictureURL1", * 32 33 34 35 36 37 38 39 40 41 42 * "PictureURL2", "PictureURL3", "UserBool1", "UserBool2", "UserBool3", "UserBool4", "UserBool5", "UserString1", "UserString2", "UserString3", "UserString4", * 43 44 45 46 47 48 49 * "UserString5", "UserInt1", "UserInt2", "UserInt3", "UserInt4", "UserInt5", "OperatorFlagCode" * * --> we use: [3] = icao, [6] = regName, [13] = airctype, [12] = manufacturer */ // Print out the content of the text field: // System.Console.WriteLine("DEBUG Output: '" + sqlite_datareader["text"] + "'"); var icao = sqlite_datareader.GetString(3).ToUpperInvariant(); var regName = sqlite_datareader.GetValue(6).ToString( ).ToUpperInvariant( ); var airctype = sqlite_datareader.GetValue(13).ToString( ).ToUpperInvariant( ); var manufacturer = sqlite_datareader.GetValue(12).ToString( ); var airctypename = sqlite_datareader.GetValue(16).ToString( ); airctype = (airctype == "0000") ? "" : airctype; // fix NULL manufacturer = manufacturer.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) airctypename = airctypename.Replace("'", "`"); // cannot have single quotes for SQL (and don't want to escape...) var rec = new icaoRec(icao, regName, airctype, manufacturer); if (rec.IsValid) { ret += idb.Add(rec); // collect adding information } }//while } //reader } //cmd m_dbc.Close( ); m_dbc.Dispose( ); } return(ret); }