Esempio n. 1
0
        public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit)
        {
            var trimSelect = "SELECT ";

            if (select.Count > 0 && select[0].Sql.StartsWith(trimSelect))
            {
                var selectBuilder = new SqlStatementBuilder(select);
                var remaining     = select[0].Sql.Substring(trimSelect.Length);
                selectBuilder.Parts[0] = new SqlLiteralPart(remaining);
                return(SqlStatement.Format("SELECT TOP ({0}) {1}", limit, selectBuilder.ToSqlStatement()));
            }
            throw new ArgumentException("S0051: Unknown select format");
        }
Esempio n. 2
0
        public BulkQuery GetDeleteAllQuery <T>(DataContext dataContext)
        {
            var sqlProvider = dataContext.Vendor.SqlProvider;
            var rowType     = typeof(T);
            var table       = dataContext.Mapping.GetTable(rowType);

            var deleteBuilder = new SqlStatementBuilder("DELETE FROM ");

            deleteBuilder.Append(sqlProvider.GetTable(table.TableName));
            return(new BulkQuery {
                DataContext = dataContext, Sql = deleteBuilder.ToSqlStatement()
            });
        }
Esempio n. 3
0
        public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit)
        {
            // return string.Format("SELECT FIRST {0} FROM ({1})", limit, select);
            var trimSelect = "SELECT ";

            if (select.Count > 0 && select[0].Sql.StartsWith(trimSelect))
            {
                var selectBuilder = new SqlStatementBuilder(select);
                var remaining     = select[0].Sql.Substring(trimSelect.Length);
                selectBuilder.Parts[0] = new SqlLiteralPart(remaining);
                return(SqlStatement.Format("SELECT FIRST {0} {1}", limit, selectBuilder.ToSqlStatement()));
            }
            throw new ArgumentException("Invalid SELECT format");
        }
Esempio n. 4
0
        public BulkQuery GetExistsQuery <T>(DataContext dataContext)
        {
            BulkQuery result = null;

            if (ExistsQueryCache.TryGetValue(typeof(T), out result))
            {
                if (result.DataContext == dataContext)
                {
                    return(result);
                }
            }

            var upsertParameters = GetUpsertParameters <T>(true, Columns <T>(), dataContext);
            var sqlProvider      = dataContext.Vendor.SqlProvider;
            var sqlBuilder       = new SqlStatementBuilder("SELECT COUNT (*) FROM ");

            sqlBuilder.Append(sqlProvider.GetTable(upsertParameters.Table.TableName));
            sqlBuilder.Append(" WHERE ");
            var valueSet = false;

            for (IEnumerator <SqlStatement> column = upsertParameters.InputPKColumns.GetEnumerator(), value = upsertParameters.InputPKValues.GetEnumerator(); column.MoveNext() && value.MoveNext();)
            {
                if (valueSet)
                {
                    sqlBuilder.Append(" AND ");
                }
                sqlBuilder.AppendFormat("{0} = {1}", column.Current, value.Current);
                valueSet = true;
            }

            result = new BulkQuery {
                DataContext          = dataContext,
                Sql                  = sqlBuilder.ToSqlStatement(),
                InputParameters      = upsertParameters.PKParameters,
                PrimaryKeyParameters = upsertParameters.PKParameters
            };
            ExistsQueryCache[typeof(T)] = result;
            return(result);
        }