private string FormatQuery(string command) { Reset(); _sql.Append(command); string tableName = SqlHelpers.FormatTableName(_query.TableName); _sql.AppendFormat(" FROM {0}", tableName); if (_query.Filter != null) { FormatWhereClause(_query.Filter); } if (_query.Ordering.Count > 0) { FormatOrderByClause(_query.Ordering); } if (_query.Skip.HasValue || _query.Top.HasValue) { FormatLimitClause(_query.Top, _query.Skip); } return(GetSql()); }
private void FormatCountQuery() { string tableName = SqlHelpers.FormatTableName(_query.TableName); _sql.AppendFormat("SELECT COUNT(1) AS [count] FROM {0}", tableName); if (_query.Filter != null) { FormatWhereClause(_query.Filter); } }
public string FormatDelete() { var delQuery = _query.Clone(); // create a copy to avoid modifying the original delQuery.Selection.Clear(); delQuery.Selection.Add(MobileServiceSystemColumns.Id); delQuery.IncludeTotalCount = false; var formatter = new SqlQueryFormatter(delQuery); string selectIdQuery = formatter.FormatSelect(); string idMemberName = SqlHelpers.FormatMember(MobileServiceSystemColumns.Id); string tableName = SqlHelpers.FormatTableName(delQuery.TableName); string command = $"DELETE FROM {tableName} WHERE {idMemberName} IN ({selectIdQuery})"; Parameters = formatter.Parameters; return(command); }