/// <summary> /// Helper to retrieve data. /// </summary> /// <param name="statement"></param> /// <param name="position"></param> /// <returns></returns> private object GetObject(SQLiteStatement statement, int position) { try { return statement.GetText(position); } catch (Exception e) { } try { return statement.GetInteger(position); } catch (Exception e) { } try { return statement.GetFloat(position); } catch (Exception e) { } return null; }
/// <summary> /// Return JSONArray for one row of data from the statement /// </summary> /// <param name="statement"></param> /// <returns></returns> private JArray GetDataFromRow(SQLiteStatement statement) { var row = new JArray(); int columnCount = statement.ColumnCount; for (int i = 0; i < columnCount; i++) { if (statement.ColumnName(i).EndsWith(SoupCol)) { string raw = statement.GetText(i); row.Add(JObject.Parse(raw)); } else { object raw = GetObject(statement, i); if (raw != null) { long value; if (long.TryParse(raw.ToString(), out value)) { row.Add(new JValue(value)); } else { double dvalue; if (double.TryParse(raw.ToString(), out dvalue)) { row.Add(new JValue(dvalue)); } else { row.Add(raw.ToString()); } } } } } return row; }
private object GetObject(SQLiteStatement statement, int position) { if (statement[position] == null) { return null; } if (statement[position].GetType().Name == "String") { return statement.GetText(position); } if (intTypes.Contains(statement[position].GetType().Name)) { return statement.GetInteger(position); } // //fallback try to detect type using exceptions // try { return statement.GetText(position); } catch (Exception e) { } try { return statement.GetInteger(position); } catch (Exception e) { } try { return statement.GetFloat(position); } catch (Exception e) { } return null; }