1 write to sql
System.Data.Linq (1)
SqlClient\Query\SqlMethodCallConverter.cs (1)
637
this.
sql
= sql;
615 references to sql
System.Data.Linq (615)
SqlClient\Query\SqlMethodCallConverter.cs (615)
657
return
sql
.ConvertTo(newType, uo.SqlType, expr);
695
return
sql
.Case(tc.ClrType, tc.Discriminator, matches, values, tc.SourceExpression);
722
return
sql
.FunctionCall(typeof(string), "REPLICATE", new SqlExpression[] { sox.Args[0], sox.Args[1] }, sox.SourceExpression);
734
SqlExpression char2 =
sql
.FunctionCall(typeof(void), "NCHAR", new SqlExpression[1] {
sql
.ValueFromObject(2, false, source) }, source);
735
SqlExpression char4 =
sql
.FunctionCall(typeof(void), "NCHAR", new SqlExpression[1] {
sql
.ValueFromObject(4, false, source) }, source);
736
SqlExpression year =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char4, sox.Args[0] }, source);
737
SqlExpression month =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[1] }, source);
738
SqlExpression day =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[2] }, source);
741
SqlExpression date =
sql
.Concat(month,
sql
.ValueFromObject("/", false, source), day,
sql
.ValueFromObject("/", false, source), year);
742
return
sql
.FunctionCall(typeof(DateTime), "CONVERT", new SqlExpression[3] { datetime, date,
sql
.ValueFromObject(101, false, source) }, source);
749
SqlExpression hour =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[3] }, source);
750
SqlExpression minute =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[4] }, source);
751
SqlExpression second =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[5] }, source);
752
SqlExpression date =
sql
.Concat(year,
sql
.ValueFromObject("-", false, source), month,
sql
.ValueFromObject("-", false, source), day);
753
SqlExpression time =
sql
.Concat(hour,
sql
.ValueFromObject(":", false, source), minute,
sql
.ValueFromObject(":", false, source), second);
754
SqlExpression dateAndTime =
sql
.Concat(date,
sql
.ValueFromObject(' ', false, source), time);
756
return
sql
.FunctionCall(typeof(DateTime), "CONVERT", new SqlExpression[3] { datetime, dateAndTime,
sql
.ValueFromObject(120, false, source) }, source);
761
SqlExpression msRaw =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] {char4,
762
sql
.Add(
sql
.ValueFromObject(1000, false, source),sox.Args[6])}, source);
766
SqlExpression len =
sql
.FunctionCall(typeof(int), "LEN", new SqlExpression[1] { msRaw }, source);
767
SqlExpression startIndex =
sql
.Binary(SqlNodeType.Sub, len,
sql
.ValueFromObject(2, false, source));
768
ms =
sql
.FunctionCall(typeof(string), "SUBSTRING", new SqlExpression[3] { msRaw, startIndex,
sql
.ValueFromObject(3, false, source) }, source);
771
ms =
sql
.FunctionCall(typeof(string), "RIGHT", new SqlExpression[2] { msRaw,
sql
.ValueFromObject(3, false, source) }, source);
773
dateAndTime =
sql
.Concat(dateAndTime,
sql
.ValueFromObject('.', false, source), ms);
774
return
sql
.FunctionCall(typeof(DateTime), "CONVERT", new SqlExpression[3] { datetime, dateAndTime,
sql
.ValueFromObject(121, false, source) }, source);
787
return
sql
.FunctionCall(typeof(DateTimeOffset), "TODATETIMEOFFSET",
788
new SqlExpression[2] { sox.Args[0],
sql
.ValueFromObject(0, false, source) },
794
return
sql
.FunctionCall(typeof(DateTimeOffset), "TODATETIMEOFFSET",
798
sql
.ConvertToInt(
sql
.ConvertToBigint(
sql
.Divide(
sql
.ConvertTimeToDouble(sox.Args[1]), TimeSpan.TicksPerMinute)))
808
SqlExpression char2 =
sql
.FunctionCall(typeof(void), "NCHAR", new SqlExpression[1] {
sql
.ValueFromObject(2, false, source) }, source);
809
SqlExpression char4 =
sql
.FunctionCall(typeof(void), "NCHAR", new SqlExpression[1] {
sql
.ValueFromObject(4, false, source) }, source);
810
SqlExpression char5 =
sql
.FunctionCall(typeof(void), "NCHAR", new SqlExpression[1] {
sql
.ValueFromObject(5, false, source) }, source);
813
SqlExpression yyRaw =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] {char5,
814
sql
.Add(
sql
.ValueFromObject(10000, false, source),sox.Args[0])}, source);
815
SqlExpression year =
sql
.FunctionCall(typeof(string), "RIGHT", new SqlExpression[2] { yyRaw,
sql
.ValueFromObject(4, false, source) }, source);
817
SqlExpression month =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[1] }, source);
818
SqlExpression day =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[2] }, source);
820
SqlExpression hour =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[3] }, source);
821
SqlExpression minute =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[4] }, source);
822
SqlExpression second =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] { char2, sox.Args[5] }, source);
823
SqlExpression date =
sql
.Concat(year,
sql
.ValueFromObject("-", false, source), month,
sql
.ValueFromObject("-", false, source), day);
824
SqlExpression time =
sql
.Concat(hour,
sql
.ValueFromObject(":", false, source), minute,
sql
.ValueFromObject(":", false, source), second);
832
dateAndTime =
sql
.Concat(date,
sql
.ValueFromObject(' ', false, source), time);
833
result =
sql
.FunctionCall(typeof(DateTimeOffset), "CONVERT", new SqlExpression[3] { datetimeoffset, dateAndTime,
sql
.ValueFromObject(120, false, source) }, source);
838
SqlExpression msRaw =
sql
.FunctionCall(typeof(string), "CONVERT", new SqlExpression[2] {char4,
839
sql
.Add(
sql
.ValueFromObject(1000, false, source),sox.Args[6])}, source);
840
SqlExpression ms =
sql
.FunctionCall(typeof(string), "RIGHT", new SqlExpression[2] { msRaw,
sql
.ValueFromObject(3, false, source) }, source);
841
dateAndTime =
sql
.Concat(date,
sql
.ValueFromObject(' ', false, source), time,
sql
.ValueFromObject('.', false, source), ms);
842
result =
sql
.FunctionCall(typeof(DateTimeOffset), "CONVERT", new SqlExpression[3] { datetimeoffset, dateAndTime,
sql
.ValueFromObject(121, false, source) }, source);
848
return
sql
.FunctionCall(typeof(DateTimeOffset), "TODATETIMEOFFSET",
852
sql
.ConvertToInt(
sql
.ConvertToBigint(
sql
.Divide(
sql
.ConvertTimeToDouble(sox.Args[timeSpanIndex]), TimeSpan.TicksPerMinute)))
862
return
sql
.ConvertTo(typeof(TimeSpan), sox.Args[0]);
866
SqlExpression hours =
sql
.ConvertToBigint(sox.Args[0]);
867
SqlExpression minutes =
sql
.ConvertToBigint(sox.Args[1]);
868
SqlExpression seconds =
sql
.ConvertToBigint(sox.Args[2]);
869
SqlExpression TicksFromHours =
sql
.Multiply(hours, TimeSpan.TicksPerHour);
870
SqlExpression TicksFromMinutes =
sql
.Multiply(minutes, TimeSpan.TicksPerMinute);
871
SqlExpression TicksFromSeconds =
sql
.Multiply(seconds, TimeSpan.TicksPerSecond);
872
return
sql
.ConvertTo(typeof(TimeSpan),
sql
.Add(TicksFromHours, TicksFromMinutes, TicksFromSeconds));
875
SqlExpression days =
sql
.ConvertToBigint(sox.Args[0]);
876
SqlExpression hours =
sql
.ConvertToBigint(sox.Args[1]);
877
SqlExpression minutes =
sql
.ConvertToBigint(sox.Args[2]);
878
SqlExpression seconds =
sql
.ConvertToBigint(sox.Args[3]);
879
SqlExpression TicksFromDays =
sql
.Multiply(days, TimeSpan.TicksPerDay);
880
SqlExpression TicksFromHours =
sql
.Multiply(hours, TimeSpan.TicksPerHour);
881
SqlExpression TicksFromMinutes =
sql
.Multiply(minutes, TimeSpan.TicksPerMinute);
882
SqlExpression TicksFromSeconds =
sql
.Multiply(seconds, TimeSpan.TicksPerSecond);
883
SqlExpression totalTicks =
sql
.Add(TicksFromDays, TicksFromHours, TicksFromMinutes, TicksFromSeconds);
886
return
sql
.ConvertTo(typeof(TimeSpan), totalTicks);
890
SqlExpression milliseconds =
sql
.ConvertToBigint(sox.Args[4]);
891
SqlExpression ticksFromMs =
sql
.Multiply(milliseconds, TimeSpan.TicksPerMillisecond);
892
return
sql
.ConvertTo(typeof(TimeSpan),
sql
.Add(totalTicks, ticksFromMs));
909
returnValue =
sql
.ConvertTo(mc.ClrType, mc.Arguments[0]);
950
return
sql
.Binary(SqlNodeType.EQ, mc.Object, mc.Arguments[0]);
959
return
sql
.ConvertTo(typeof(string), expr);
1002
return
sql
.Binary(SqlNodeType.Coalesce, mc.Object,
1003
sql
.ValueFromObject(Activator.CreateInstance(clrType), mc.SourceExpression));
1006
return
sql
.Binary(SqlNodeType.Coalesce, mc.Object, mc.Arguments[0]);
1020
return
sql
.FunctionCall(typeof(int), "DATEDIFF",
1027
return
sql
.Like(mc.Arguments[0], mc.Arguments[1], null, source);
1030
return
sql
.Like(mc.Arguments[0], mc.Arguments[1],
sql
.ConvertTo(typeof(string), mc.Arguments[2]), source);
1034
SqlExpression length =
sql
.DATALENGTH(mc.Arguments[0]);
1042
SqlExpression lower =
sql
.Binary(SqlNodeType.LT, a, b);
1043
SqlExpression equal =
sql
.Binary(SqlNodeType.EQ2V, a, b);
1044
return
sql
.SearchedCase(
1046
new SqlWhen(lower,
sql
.ValueFromObject(-1, false, source)),
1047
new SqlWhen(equal,
sql
.ValueFromObject(0, false, source)),
1049
sql
.ValueFromObject(1, false, source), source
1065
SqlExpression ns = this.
sql
.DATEPART("NANOSECOND", mc.Arguments[0]);
1066
SqlExpression ss = this.
sql
.DATEPART("SECOND", mc.Arguments[0]);
1067
SqlExpression mm = this.
sql
.DATEPART("MINUTE", mc.Arguments[0]);
1068
SqlExpression hh = this.
sql
.DATEPART("HOUR", mc.Arguments[0]);
1069
sqlTicks =
sql
.Add(
1070
sql
.Divide(ns, 100),
1071
sql
.Multiply(
1072
sql
.Add(
1073
sql
.Multiply(
sql
.ConvertToBigint(hh), 3600000),
1074
sql
.Multiply(
sql
.ConvertToBigint(mm), 60000),
1075
sql
.Multiply(
sql
.ConvertToBigint(ss), 1000)
1084
returnValue =
sql
.DATEADD("MONTH", mc.Arguments[0], mc.Object);
1088
returnValue =
sql
.DATEADD("YEAR", mc.Arguments[0], mc.Object);
1097
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 1000);
1101
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 60000);
1105
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 3600000);
1109
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 86400000);
1123
SqlExpression ns =
sql
.DATEPART("NANOSECOND", mc.Arguments[0]);
1124
SqlExpression ss =
sql
.DATEPART("SECOND", mc.Arguments[0]);
1125
SqlExpression mi =
sql
.DATEPART("MINUTE", mc.Arguments[0]);
1126
SqlExpression hh =
sql
.DATEPART("HOUR", mc.Arguments[0]);
1128
SqlExpression ticks =
sql
.Add(
1129
sql
.Divide(ns, 100),
1130
sql
.Multiply(
1131
sql
.Add(
1132
sql
.Multiply(
sql
.ConvertToBigint(hh), 3600000),
1133
sql
.Multiply(
sql
.ConvertToBigint(mi), 60000),
1134
sql
.Multiply(
sql
.ConvertToBigint(ss), 1000)
1143
returnValue =
sql
.DATETIMEOFFSETADD("MONTH", mc.Arguments[0], mc.Object);
1147
returnValue =
sql
.DATETIMEOFFSETADD("YEAR", mc.Arguments[0], mc.Object);
1156
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 1000);
1160
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 60000);
1164
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 3600000);
1168
SqlExpression ms =
sql
.Multiply(mc.Arguments[0], 86400000);
1178
returnValue =
sql
.Add(mc.Object, mc.Arguments[0]);
1181
returnValue =
sql
.Subtract(mc.Object, mc.Arguments[0]);
1190
returnValue =
sql
.FunctionCall(typeof(TimeSpan), "ABS", new SqlExpression[] { mc.Object }, source);
1193
returnValue =
sql
.Unary(SqlNodeType.Negate, mc.Object, source);
1217
providerType =
sql
.TypeProvider.From(targetType, 1);
1261
if (
sql
.TypeProvider.From(targetType) != expr.SqlType ||
1264
returnValue =
sql
.ConvertTo(targetType, expr);
1267
if (
sql
.TypeProvider.From(targetType) != expr.SqlType) {
1269
returnValue =
sql
.ConvertTo(targetType, expr);
1299
SqlExpression intDays =
sql
.FunctionCall(typeof(int), "DATEDIFF",
1301
SqlExpression startPlusDays =
sql
.FunctionCall(
1303
SqlExpression intMSec =
sql
.FunctionCall(typeof(int), "DATEDIFF",
1305
SqlExpression result =
sql
.Multiply(
sql
.Add(
sql
.Multiply(
sql
.ConvertToBigint(intDays), 86400000), intMSec), 10000); // 1 millisecond = 10000 ticks
1306
return
sql
.ConvertTo(resultType, result);
1320
SqlExpression intDays =
sql
.FunctionCall(typeof(int), "DATEDIFF", new SqlExpression[] { day, start, end }, bo.SourceExpression);
1321
SqlExpression startPlusDays =
sql
.FunctionCall(typeof(DateTimeOffset), "DATEADD", new SqlExpression[] { day, intDays, start }, bo.SourceExpression);
1322
SqlExpression intMSec =
sql
.FunctionCall(typeof(int), "DATEDIFF", new SqlExpression[] { ms, startPlusDays, end }, bo.SourceExpression);
1323
SqlExpression startPlusDaysPlusMsec =
sql
.FunctionCall(typeof(DateTimeOffset), "DATEADD", new SqlExpression[] { ms, intMSec, startPlusDays }, bo.SourceExpression);
1324
SqlExpression intUSec =
sql
.FunctionCall(typeof(int), "DATEDIFF", new SqlExpression[] { us, startPlusDaysPlusMsec, end }, bo.SourceExpression);
1325
SqlExpression startPlusDaysPlusMsecPlusUSec =
sql
.FunctionCall(typeof(DateTimeOffset), "DATEADD", new SqlExpression[] { us, intUSec, startPlusDaysPlusMsec }, bo.SourceExpression);
1326
SqlExpression intNSec =
sql
.FunctionCall(typeof(int), "DATEDIFF", new SqlExpression[] { ns, startPlusDaysPlusMsecPlusUSec, end }, bo.SourceExpression);
1327
SqlExpression startPlusDaysPlusMsecPlusUSecPlusNSec =
sql
.FunctionCall(typeof(DateTimeOffset), "DATEADD", new SqlExpression[] { ns, intNSec, startPlusDaysPlusMsecPlusUSec }, bo.SourceExpression);
1329
SqlExpression result =
sql
.Add(
1330
sql
.Divide(intNSec, 100),
1331
sql
.Multiply(intUSec, 10),
1332
sql
.Multiply(
1333
sql
.Add(
1334
sql
.Multiply(
sql
.ConvertToBigint(intDays), 86400000),
1340
return
sql
.ConvertTo(resultType, result);
1345
SqlExpression ns =
sql
.DATEPART("NANOSECOND", right);
1346
SqlExpression ss =
sql
.DATEPART("SECOND", right);
1347
SqlExpression mi =
sql
.DATEPART("MINUTE", right);
1348
SqlExpression hh =
sql
.DATEPART("HOUR", right);
1350
right =
sql
.Add(
1351
sql
.Divide(ns, 100),
1352
sql
.Multiply(
1353
sql
.Add(
1354
sql
.Multiply(
sql
.ConvertToBigint(hh), 3600000),
1355
sql
.Multiply(
sql
.ConvertToBigint(mi), 60000),
1356
sql
.Multiply(
sql
.ConvertToBigint(ss), 1000)
1366
sql
.Unary(SqlNodeType.Negate, right, bo.SourceExpression),
1371
sql
.Unary(SqlNodeType.Negate, right, bo.SourceExpression),
1379
return
sql
.AddTimeSpan(bo.Left, bo.Right, resultNullable);
1397
return
sql
.Binary(SqlNodeType.Mul, mc.Arguments[0], mc.Arguments[1]);
1399
return
sql
.Binary(SqlNodeType.Div, mc.Arguments[0], mc.Arguments[1]);
1401
return
sql
.Binary(SqlNodeType.Sub, mc.Arguments[0], mc.Arguments[1]);
1403
return
sql
.Binary(SqlNodeType.Add, mc.Arguments[0], mc.Arguments[1]);
1405
return
sql
.Binary(SqlNodeType.Mod, mc.Arguments[0], mc.Arguments[1]);
1408
return
sql
.FunctionCall(mc.Method.ReturnType, "ROUND", mc.Arguments, mc.SourceExpression);
1414
return
sql
.Unary(SqlNodeType.Negate, mc.Arguments[0], source);
1418
return
sql
.FunctionCall(mc.Method.ReturnType, "ROUND",
1421
sql
.ValueFromObject(0, false, mc.SourceExpression),
1422
sql
.ValueFromObject(1, false, mc.SourceExpression)
1427
return
sql
.FunctionCall(mc.Method.ReturnType, "ROUND",
1430
sql
.ValueFromObject(0, false, mc.SourceExpression)
1458
returnValue =
sql
.ValueFromObject("", false, source);
1466
sum =
sql
.ConvertTo(typeof(string), exprs[0]);
1470
sum =
sql
.Concat(sum, exprs[i]);
1473
sum =
sql
.Concat(sum,
sql
.ConvertTo(typeof(string), exprs[i]));
1480
returnValue =
sql
.Binary(SqlNodeType.EQ2V, mc.Arguments[0], mc.Arguments[1]);
1492
return
sql
.FunctionCall(type, functionName, new SqlExpression[] { arguments[0] }, source);
1496
return
sql
.FunctionCall(type, functionName, new SqlExpression[] { arguments[0], arguments[1] }, source);
1512
pattern =
sql
.ValueFromObject(patternText, true, pattern.SourceExpression);
1531
escape =
sql
.ValueFromObject("~", false, source);
1534
return
sql
.Like(mc.Object, pattern, escape, source);
1546
pattern =
sql
.ValueFromObject(patternText, true, pattern.SourceExpression);
1565
escape =
sql
.ValueFromObject("~", false, source);
1568
return
sql
.Like(mc.Object, pattern, escape, source);
1580
pattern =
sql
.ValueFromObject(patternText, true, pattern.SourceExpression);
1599
escape =
sql
.ValueFromObject("~", false, source);
1602
return
sql
.Like(mc.Object, pattern, escape, source);
1611
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1612
SqlWhen when = new SqlWhen(lenZeroExpr,
sql
.ValueFromObject(0, source));
1613
SqlExpression @else =
sql
.Subtract(
sql
.FunctionCall(typeof(int), "CHARINDEX",
1618
return
sql
.SearchedCase(new SqlWhen[] { when }, @else, source);
1630
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1631
lenZeroExpr =
sql
.AndAccumulate(lenZeroExpr,
sql
.Binary(SqlNodeType.LE,
sql
.Add(mc.Arguments[1], 1),
sql
.CLRLENGTH(mc.Object)));
1633
SqlExpression @else =
sql
.Subtract(
sql
.FunctionCall(typeof(int), "CHARINDEX",
1637
sql
.Add(mc.Arguments[1], 1)
1640
return
sql
.SearchedCase(new SqlWhen[] { when }, @else, source);
1653
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1654
lenZeroExpr =
sql
.AndAccumulate(lenZeroExpr,
sql
.Binary(SqlNodeType.LE,
sql
.Add(mc.Arguments[1], 1),
sql
.CLRLENGTH(mc.Object)));
1656
SqlExpression substring =
sql
.FunctionCall(
1660
sql
.ValueFromObject(1, false, source),
1661
sql
.Add(mc.Arguments[1], mc.Arguments[2])
1664
SqlExpression @else =
sql
.Subtract(
sql
.FunctionCall(typeof(int), "CHARINDEX",
1668
sql
.Add(mc.Arguments[1], 1)
1671
return
sql
.SearchedCase(new SqlWhen[] { when }, @else, source);
1685
SqlExpression reverseS =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { exprS }, source);
1686
SqlExpression reversePart =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { exprPart }, source);
1687
SqlExpression charIndex =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { exprPart, exprS }, source);
1688
SqlExpression charIndexOfReverse =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { reversePart, reverseS }, source);
1689
SqlExpression notContained =
sql
.Binary(SqlNodeType.EQ, charIndex,
sql
.ValueFromObject(0, false, source));
1690
SqlExpression len1 =
sql
.CLRLENGTH(exprS);
1691
SqlExpression len2 =
sql
.CLRLENGTH(exprPart);
1692
SqlExpression elseCase =
sql
.Add(
sql
.ValueFromObject(1, false, source),
sql
.Subtract(len1,
sql
.Add(len2, charIndexOfReverse)));
1694
SqlWhen whenNotContained = new SqlWhen(notContained,
sql
.ValueFromObject(-1, false, source));
1697
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1698
SqlWhen whenLenZero = new SqlWhen(lenZeroExpr,
sql
.Subtract(
sql
.CLRLENGTH(exprS), 1));
1700
return
sql
.SearchedCase(new SqlWhen[] { whenLenZero, whenNotContained },
1718
SqlExpression first =
sql
.FunctionCall(typeof(string), "LEFT", new SqlExpression[] { s,
sql
.Add(i, 1) }, source);
1719
SqlExpression reverseFirst =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { first }, source);
1720
SqlExpression reversePart =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { part }, source);
1721
SqlExpression charIndex =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { part, first }, source);
1722
SqlExpression charIndexOfReverse =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { reversePart, reverseFirst }, source);
1723
SqlExpression notContained =
sql
.Binary(SqlNodeType.EQ, charIndex,
sql
.ValueFromObject(0, false, source));
1724
SqlExpression len1 =
sql
.CLRLENGTH(first);
1725
SqlExpression len2 =
sql
.CLRLENGTH(part);
1726
SqlExpression elseCase =
sql
.Add(
sql
.ValueFromObject(1, false, source),
sql
.Subtract(len1,
sql
.Add(len2, charIndexOfReverse)));
1728
SqlWhen whenNotContained = new SqlWhen(notContained,
sql
.ValueFromObject(-1, false, source));
1732
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1733
lenZeroExpr =
sql
.AndAccumulate(lenZeroExpr,
sql
.Binary(SqlNodeType.LE,
sql
.Add(mc.Arguments[1], 1),
sql
.CLRLENGTH(s)));
1736
return
sql
.SearchedCase(new SqlWhen[] { whenLenZero, whenNotContained },
1755
SqlExpression first =
sql
.FunctionCall(typeof(string), "LEFT", new SqlExpression[] { s,
sql
.Add(i, 1) }, source);
1756
SqlExpression reverseFirst =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { first }, source);
1757
SqlExpression reversePart =
sql
.FunctionCall(typeof(string), "REVERSE", new SqlExpression[] { part }, source);
1758
SqlExpression charIndex =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { part, first }, source);
1759
SqlExpression charIndexOfReverse =
sql
.FunctionCall(typeof(int), "CHARINDEX", new SqlExpression[] { reversePart, reverseFirst }, source);
1760
SqlExpression len1 =
sql
.CLRLENGTH(first);
1761
SqlExpression len2 =
sql
.CLRLENGTH(part);
1762
SqlExpression elseCase =
sql
.Add(
sql
.ValueFromObject(1, false, source),
sql
.Subtract(len1,
sql
.Add(len2, charIndexOfReverse)));
1763
SqlExpression notContained =
sql
.Binary(SqlNodeType.EQ, charIndex,
sql
.ValueFromObject(0, false, source));
1764
notContained =
sql
.OrAccumulate(notContained,
sql
.Binary(SqlNodeType.LE, elseCase,
sql
.Subtract(i, count)));
1766
SqlWhen whenNotContained = new SqlWhen(notContained,
sql
.ValueFromObject(-1, false, source));
1770
SqlExpression lenZeroExpr =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Arguments[0]),
sql
.ValueFromObject(0, source));
1771
lenZeroExpr =
sql
.AndAccumulate(lenZeroExpr,
sql
.Binary(SqlNodeType.LE,
sql
.Add(mc.Arguments[1], 1),
sql
.CLRLENGTH(s)));
1774
return
sql
.SearchedCase(new SqlWhen[] { whenLenZero, whenNotContained },
1784
SqlFunctionCall stuffCall =
sql
.FunctionCall(
1788
sql
.Add(mc.Arguments[0], 1),
1789
sql
.ValueFromObject(0, false, source),
1798
SqlExpression insertingAtEnd =
sql
.Binary(SqlNodeType.EQ,
sql
.CLRLENGTH(mc.Object), mc.Arguments[0]);
1799
SqlExpression stringConcat =
sql
.Concat(mc.Object, mc.Arguments[1]);
1801
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(insertingAtEnd, stringConcat) }, stuffCall, source);
1812
SqlExpression len2 =
sql
.CLRLENGTH(exprS);
1813
SqlExpression dontChange =
sql
.Binary(SqlNodeType.GE, len2, exprI);
1814
SqlExpression numSpaces =
sql
.Subtract(exprI, len2);
1815
SqlExpression padding =
sql
.FunctionCall(typeof(string), "SPACE", new SqlExpression[] { numSpaces }, source);
1816
SqlExpression elseCase =
sql
.Concat(padding, exprS);
1818
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(dontChange, exprS) }, elseCase, source);
1828
SqlExpression dontChange =
sql
.Binary(SqlNodeType.GE,
sql
.CLRLENGTH(exprS), exprI);
1829
SqlExpression len2 =
sql
.CLRLENGTH(exprS);
1830
SqlExpression numSpaces =
sql
.Subtract(exprI, len2);
1831
SqlExpression padding =
sql
.FunctionCall(typeof(string), "REPLICATE", new SqlExpression[] { exprC, numSpaces }, source);
1832
SqlExpression elseCase =
sql
.Concat(padding, exprS);
1834
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(dontChange, exprS) }, elseCase, source);
1845
SqlExpression dontChange =
sql
.Binary(SqlNodeType.GE,
sql
.CLRLENGTH(exprS), exprI);
1846
SqlExpression len2 =
sql
.CLRLENGTH(exprS);
1847
SqlExpression numSpaces =
sql
.Subtract(exprI, len2);
1848
SqlExpression padding =
sql
.FunctionCall(typeof(string), "SPACE", new SqlExpression[] { numSpaces }, source);
1849
SqlExpression elseCase =
sql
.Concat(exprS, padding);
1851
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(dontChange, exprS) }, elseCase, source);
1861
SqlExpression dontChange =
sql
.Binary(SqlNodeType.GE,
sql
.CLRLENGTH(exprS), exprI);
1862
SqlExpression len2 =
sql
.CLRLENGTH(exprS);
1863
SqlExpression numSpaces =
sql
.Subtract(exprI, len2);
1864
SqlExpression padding =
sql
.FunctionCall(typeof(string), "REPLICATE", new SqlExpression[] { exprC, numSpaces }, source);
1865
SqlExpression elseCase =
sql
.Concat(exprS, padding);
1867
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(dontChange, exprS) }, elseCase, source);
1873
return
sql
.FunctionCall(
1877
sql
.Add(mc.Arguments[0], 1),
1878
sql
.CLRLENGTH(mc.Object),
1879
sql
.ValueFromObject("", false, source)
1884
return
sql
.FunctionCall(
1888
sql
.Add(mc.Arguments[0], 1),
1890
sql
.ValueFromObject("", false, source)
1902
return
sql
.FunctionCall(
1912
return
sql
.FunctionCall(
1916
sql
.Add(mc.Arguments[0], 1),
1917
sql
.CLRLENGTH(mc.Object)
1922
return
sql
.FunctionCall(
1926
sql
.Add(mc.Arguments[0], 1),
1934
return
sql
.FunctionCall(
1937
sql
.FunctionCall(typeof(string), "RTRIM", new SqlExpression[] { mc.Object }, source)
1944
return
sql
.FunctionCall(typeof(string), "LOWER", new SqlExpression[] { mc.Object }, source);
1949
return
sql
.FunctionCall(typeof(string), "UPPER", new SqlExpression[] { mc.Object }, source);
1955
return
sql
.FunctionCall(typeof(char), "SUBSTRING", new SqlExpression[]
1957
sql
.Add( mc.Arguments[0], 1),
1958
sql
.ValueFromObject(1, false, source)
1979
return
sql
.FunctionCall(mc.Arguments[0].ClrType, "ABS", new SqlExpression[] { mc.Arguments[0] }, source);
2004
return
sql
.Multiply(
sql
.ConvertToBigint(mc.Arguments[0]),
sql
.ConvertToBigint(mc.Arguments[1]));
2020
SqlExpression expX =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { x }, source);
2021
SqlExpression minusX =
sql
.Unary(SqlNodeType.Negate, x, source);
2022
SqlExpression expMinusX =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { minusX }, source);
2023
return
sql
.Divide(
sql
.Add(expX, expMinusX), 2);
2044
SqlExpression log1 =
sql
.FunctionCall(typeof(double), "LOG", new SqlExpression[] { mc.Arguments[0] }, source);
2045
SqlExpression log2 =
sql
.FunctionCall(typeof(double), "LOG", new SqlExpression[] { mc.Arguments[1] }, source);
2046
return
sql
.Divide(log1, log2);
2059
SqlExpression aLower =
sql
.Binary(SqlNodeType.LT, a, b);
2068
SqlExpression aLower =
sql
.Binary(SqlNodeType.LT, a, b);
2069
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(aLower, a) }, b, source);
2086
i =
sql
.ValueFromObject(0, false, source);
2097
return
sql
.FunctionCall(x.ClrType, "round", new SqlExpression[] { x, i }, source);
2105
SqlExpression roundX =
sql
.FunctionCall(type, "round", new SqlExpression[] { x, i }, source);
2106
SqlExpression twiceX =
sql
.Multiply(x, 2);
2107
SqlExpression round2X =
sql
.FunctionCall(type, "round", new SqlExpression[] { twiceX, i }, source);
2108
SqlExpression condition =
sql
.AndAccumulate(
sql
.Binary(SqlNodeType.EQ, twiceX, round2X),
sql
.Binary(SqlNodeType.NE, x, roundX));
2109
SqlExpression specialCase =
sql
.Multiply(
sql
.FunctionCall(type, "round", new SqlExpression[] {
sql
.Divide(x, 2), i }, source), 2);
2110
return
sql
.SearchedCase(new SqlWhen[] { new SqlWhen(condition, specialCase) }, roundX, source);
2115
return
sql
.FunctionCall(typeof(int), "SIGN", new SqlExpression[] { mc.Arguments[0] }, source);
2126
SqlExpression exp =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { x }, source);
2127
SqlExpression minusX =
sql
.Unary(SqlNodeType.Negate, x, source);
2128
SqlExpression expMinus =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { minusX }, source);
2129
return
sql
.Divide(
sql
.Subtract(exp, expMinus), 2);
2145
SqlExpression expX =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { x }, source);
2146
SqlExpression minusX =
sql
.Unary(SqlNodeType.Negate, x, source);
2147
SqlExpression expMinusX =
sql
.FunctionCall(typeof(double), "EXP", new SqlExpression[] { minusX }, source);
2148
return
sql
.Divide(
sql
.Subtract(expX, expMinusX),
sql
.Add(expX, expMinusX));
2155
return
sql
.FunctionCall(mc.Method.ReturnType, "ROUND", new SqlExpression[] { x,
sql
.ValueFromObject(0, false, source),
sql
.ValueFromObject(1, false, source) }, source);
2173
return
sql
.LEN(exp);
2176
return
sql
.DATALENGTH(exp);
2181
return
sql
.DATEPART(datePart, exp);
2186
return
sql
.FunctionCall(typeof(DateTime), "CONVERT", new SqlExpression[2] { date, exp }, source);
2194
SqlExpression ms =
sql
.DATEPART("MILLISECOND", exp);
2195
SqlExpression ss =
sql
.DATEPART("SECOND", exp);
2196
SqlExpression mi =
sql
.DATEPART("MINUTE", exp);
2197
SqlExpression hh =
sql
.DATEPART("HOUR", exp);
2201
result =
sql
.DATEADD("MILLISECOND",
sql
.Unary(SqlNodeType.Negate, ms), result);
2202
result =
sql
.DATEADD("SECOND",
sql
.Unary(SqlNodeType.Negate, ss), result);
2203
result =
sql
.DATEADD("MINUTE",
sql
.Unary(SqlNodeType.Negate, mi), result);
2204
result =
sql
.DATEADD("HOUR",
sql
.Unary(SqlNodeType.Negate, hh), result);
2211
return
sql
.FunctionCall(typeof(DateTime), "CONVERT", new SqlExpression[2] { datetime, exp }, source);
2214
SqlExpression hours =
sql
.DATEPART("HOUR", exp);
2215
SqlExpression minutes =
sql
.DATEPART("MINUTE", exp);
2216
SqlExpression seconds =
sql
.DATEPART("SECOND", exp);
2217
SqlExpression milliseconds =
sql
.DATEPART("MILLISECOND", exp);
2219
SqlExpression ticksFromHour =
sql
.Multiply(
sql
.ConvertToBigint(hours), TimeSpan.TicksPerHour);
2220
SqlExpression ticksFromMinutes =
sql
.Multiply(
sql
.ConvertToBigint(minutes), TimeSpan.TicksPerMinute);
2221
SqlExpression ticksFromSeconds =
sql
.Multiply(
sql
.ConvertToBigint(seconds), TimeSpan.TicksPerSecond);
2222
SqlExpression ticksFromMs =
sql
.Multiply(
sql
.ConvertToBigint(milliseconds), TimeSpan.TicksPerMillisecond);
2223
return
sql
.ConvertTo(typeof(TimeSpan),
sql
.Add(ticksFromHour, ticksFromMinutes, ticksFromSeconds, ticksFromMs));
2227
SqlExpression sqlDay =
sql
.DATEPART("dw", exp);
2231
return
sql
.ConvertTo(typeof(DayOfWeek),
2232
sql
.Mod(
2233
sql
.Add(sqlDay,
2234
sql
.Add(new SqlVariable(typeof(int),
sql
.Default(typeof(int)), "@@DATEFIRST", source), 6)
2243
return this.
sql
.Divide(
2244
sql
.ConvertToBigint(
2245
sql
.Add(
2246
this.
sql
.Multiply(
sql
.ConvertToBigint(
sql
.DATEPART("HOUR", exp)), 3600000000000),
2247
this.
sql
.Multiply(
sql
.ConvertToBigint(
sql
.DATEPART("MINUTE", exp)), 60000000000),
2248
this.
sql
.Multiply(
sql
.ConvertToBigint(
sql
.DATEPART("SECOND", exp)), 1000000000),
2249
sql
.DATEPART("NANOSECOND", exp))
2254
return
sql
.ConvertToBigint(exp);
2257
return this.
sql
.Add(
2258
this.
sql
.Multiply(
sql
.DATEPART("HOUR", exp), 3600000),
2259
this.
sql
.Multiply(
sql
.DATEPART("MINUTE", exp), 60000),
2260
this.
sql
.Multiply(
sql
.DATEPART("SECOND", exp), 1000),
2261
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.ConvertToBigint(
sql
.DATEPART("NANOSECOND", exp))), 1000000)
2264
return
sql
.Divide(
sql
.ConvertToDouble(exp), TimeSpan.TicksPerMillisecond);
2267
return this.
sql
.Add(
2268
this.
sql
.Multiply(
sql
.DATEPART("HOUR", exp), 3600),
2269
this.
sql
.Multiply(
sql
.DATEPART("MINUTE", exp), 60),
2270
this.
sql
.DATEPART("SECOND", exp),
2271
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.ConvertToBigint(
sql
.DATEPART("NANOSECOND", exp))), 1000000000)
2274
return
sql
.Divide(
sql
.ConvertToDouble(exp), TimeSpan.TicksPerSecond);
2277
return this.
sql
.Add(
2278
this.
sql
.Multiply(
sql
.DATEPART("HOUR", exp), 60),
2279
this.
sql
.DATEPART("MINUTE", exp),
2280
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.DATEPART("SECOND", exp)), 60),
2281
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.ConvertToBigint(
sql
.DATEPART("NANOSECOND", exp))), 60000000000)
2284
return
sql
.Divide(
sql
.ConvertToDouble(exp), TimeSpan.TicksPerMinute);
2287
return this.
sql
.Add(
2288
this.
sql
.DATEPART("HOUR", exp),
2289
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.DATEPART("MINUTE", exp)), 60),
2290
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.DATEPART("SECOND", exp)), 3600),
2291
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.ConvertToBigint(
sql
.DATEPART("NANOSECOND", exp))), 3600000000000)
2294
return
sql
.Divide(
sql
.ConvertToDouble(exp), TimeSpan.TicksPerHour);
2297
return this.
sql
.Divide(
2298
this.
sql
.Add(
2299
this.
sql
.DATEPART("HOUR", exp),
2300
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.DATEPART("MINUTE", exp)), 60),
2301
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.DATEPART("SECOND", exp)), 3600),
2302
this.
sql
.Divide(
sql
.ConvertToDouble(
sql
.ConvertToBigint(
sql
.DATEPART("NANOSECOND", exp))), 3600000000000)),
2306
return
sql
.Divide(
sql
.ConvertToDouble(exp), TimeSpan.TicksPerDay);
2309
return this.
sql
.DATEPART("MILLISECOND", exp);
2311
return
sql
.ConvertToInt(
sql
.Mod(
sql
.ConvertToBigint(
sql
.Divide(exp, TimeSpan.TicksPerMillisecond)), 1000));
2314
return this.
sql
.DATEPART("SECOND", exp);
2316
return
sql
.ConvertToInt(
sql
.Mod(
sql
.ConvertToBigint(
sql
.Divide(exp, TimeSpan.TicksPerSecond)), 60));
2319
return this.
sql
.DATEPART("MINUTE", exp);
2321
return
sql
.ConvertToInt(
sql
.Mod(
sql
.ConvertToBigint(
sql
.Divide(exp, TimeSpan.TicksPerMinute)), 60));
2324
return this.
sql
.DATEPART("HOUR", exp);
2326
return
sql
.ConvertToInt(
sql
.Mod(
sql
.ConvertToBigint(
sql
.Divide(exp, TimeSpan.TicksPerHour)), 24));
2329
return this.
sql
.ValueFromObject(0, false, exp.SourceExpression);
2331
return
sql
.ConvertToInt(
sql
.Divide(exp, TimeSpan.TicksPerDay));
2345
SqlExpression daysAdded =
sql
.DATEADD("day",
sql
.Divide(sqlTicks, TimeSpan.TicksPerDay), sqlDate, source, asNullable);
2346
return
sql
.DATEADD("ms",
sql
.Mod(
sql
.Divide(sqlTicks, TimeSpan.TicksPerMillisecond), 86400000), daysAdded, source, asNullable);
2355
SqlExpression msBigint =
sql
.ConvertToBigint(ms);
2356
SqlExpression daysAdded =
sql
.DATEADD("day",
sql
.Divide(msBigint, 86400000), sqlDate, source, asNullable);
2357
return
sql
.DATEADD("ms",
sql
.Mod(msBigint, 86400000), daysAdded, source, asNullable);
2366
SqlExpression daysAdded =
sql
.DATETIMEOFFSETADD("day",
sql
.Divide(sqlTicks, TimeSpan.TicksPerDay), sqlDate, source, asNullable);
2367
return
sql
.DATETIMEOFFSETADD("ms",
sql
.Mod(
sql
.Divide(sqlTicks, TimeSpan.TicksPerMillisecond), 86400000), daysAdded, source, asNullable);
2376
SqlExpression msBigint =
sql
.ConvertToBigint(ms);
2377
SqlExpression daysAdded =
sql
.DATETIMEOFFSETADD("day",
sql
.Divide(msBigint, 86400000), sqlDate, source, asNullable);
2378
return
sql
.DATETIMEOFFSETADD("ms",
sql
.Mod(msBigint, 86400000), daysAdded, source, asNullable);
2441
matchesList.Add(
sql
.ValueFromObject(true, false, source));
2442
valuesList.Add(
sql
.ValueFromObject(-1, false, source));
2443
matchesList.Add(
sql
.ValueFromObject(false, false, source));
2444
valuesList.Add(
sql
.ValueFromObject(0, false, source));
2446
return
sql
.Case(targetType, expr, matchesList, valuesList, source);
2450
return
sql
.ConvertTo(targetType, expr);
2479
pattern =
sql
.ValueFromObject(patternText, typeof(string), true, source);
2496
SqlExpression escape = needsEscape ?
sql
.ValueFromObject("~", false, mc.SourceExpression) : null;
2497
return
sql
.Like(mc.Arguments[0], pattern, escape, source);