Esempio n. 1
0
        public virtual string DeleteSql(SqlTableNameWithAlias tableName, string sqlWhere, IEnumerable <SqlJoinDefinition> joins)
        {
            List <string> parts = new List <string>
            {
                "delete ",
                tableName.Alias ?? QuoteTable(tableName.TableName),
                "from",
                QuoteTable(tableName.TableName)
            };

            if (tableName.Alias != null)
            {
                parts.Add(tableName.Alias);
            }

            if (joins != null)
            {
                parts.Add(string.Join(" ", joins.Select(j => j.ToSql(this))));
            }

            if (!string.IsNullOrWhiteSpace(sqlWhere))
            {
                parts.Add("where");
                parts.Add(sqlWhere);
            }

            return(string.Join(" ", parts));
        }
Esempio n. 2
0
        public override string DeleteSql(SqlTableNameWithAlias tableName, string sqlWhere, IEnumerable <SqlJoinDefinition> joins = null)
        {
            if (joins != null && joins.Any())
            {
                throw new NotSupportedException("Sqlite does not support delete with joins");
            }

            if (tableName.Alias != null)
            {
                sqlWhere = sqlWhere?.Replace(QuoteTable(tableName.Alias) + ".", "");
            }

            return("delete from " + QuoteTable(tableName.TableName) + (sqlWhere != null ? (" where " + sqlWhere) : ""));
        }
Esempio n. 3
0
        public virtual string SelectSql(SqlTableNameWithAlias tableName, IEnumerable <SqlExpressionWithAlias> columns, string sqlWhere, IEnumerable <SqlJoinDefinition> joins = null, string sqlSortExpression = null, int?start = null, int?numRecords = null, string afterSelect = null)
        {
            var parts = new List <string>
            {
                "select",
                string.Join(",", columns.Select(c => $"{(c.ShouldQuote ? QuoteField(c.Expression) : c.Expression)} as {c.Alias}")),
                "from",
                QuoteTable(tableName.TableName)
            };

            if (afterSelect != null)
            {
                parts.Insert(1, afterSelect);
            }

            if (tableName.Alias != null)
            {
                parts.Add(tableName.Alias);
            }

            if (joins != null)
            {
                parts.Add(string.Join(" ", joins.Select(j => j.ToSql(this))));
            }

            if (!string.IsNullOrWhiteSpace(sqlWhere))
            {
                parts.Add("where");
                parts.Add(sqlWhere);
            }

            if (!string.IsNullOrWhiteSpace(sqlSortExpression))
            {
                parts.Add("order by");
                parts.Add(sqlSortExpression);
            }

            if (start != null || numRecords != null)
            {
                parts.Add("limit");

                if (start != null && numRecords == null)
                {
                    numRecords = int.MaxValue;
                }

                if (start != null)
                {
                    parts.Add((start.Value - 1).ToString());
                }

                if (start != null)
                {
                    parts.Add(",");
                }

                parts.Add(numRecords.ToString());
            }

            return(string.Join(" ", parts));
        }