/// <summary> /// Run a query given by its query spec, only returning results from the selected page. /// </summary> /// <param name="querySpec"></param> /// <param name="pageIndex"></param> /// <returns></returns> public JArray Query(QuerySpec querySpec, int pageIndex) { lock (smartlock) { QuerySpec.SmartQueryType qt = querySpec.QueryType; var results = new JArray(); string sql = ConvertSmartSql(querySpec.SmartSql); int offsetRows = querySpec.PageSize * pageIndex; int numberRows = querySpec.PageSize; string limit = offsetRows + "," + numberRows; using (ISQLiteStatement statement = DBHelper.GetInstance(DatabasePath) .LimitRawQuery(sql, limit, querySpec.getArgs())) { if (statement.DataCount > 0) { do { if (qt == QuerySpec.SmartQueryType.Smart) { results.Add(GetDataFromRow(statement)); } else { results.Add(JObject.Parse(GetObject(statement, 0).ToString())); } } while (statement.Step() == SQLiteResult.ROW); } statement.ResetAndClearBindings(); } return(results); } }
private IndexSpec[] GetIndexSpecsFromDb(String soupName) { ISQLiteStatement statement = Query(SmartStore.SoupIndexMapTable, new[] { SmartStore.PathCol, SmartStore.ColumnNameCol, SmartStore.ColumnTypeCol }, null, null, SmartStore.SoupNamePredicate, soupName); if (statement.DataCount < 1) { throw new SmartStoreException(String.Format("{0} does not have any indices", soupName)); } var indexSpecs = new List <IndexSpec>(); do { String path = statement.GetText(SmartStore.PathCol); String columnName = statement.GetText(SmartStore.ColumnNameCol); var columnType = new SmartStoreType(statement.GetText(SmartStore.ColumnTypeCol)); indexSpecs.Add(new IndexSpec(path, columnType, columnName)); } while (statement.Step() == SQLiteResult.ROW); statement.ResetAndClearBindings(); return(indexSpecs.ToArray()); }