System.Data.SQLite

Check-in [fc9e94c67d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not wrap formatted DateTime values in single quotes when they are numeric.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-8d928c3e88
Files: files | file ages | folders
SHA1: fc9e94c67dbb60687cfe4520ebb8a40bcda202db
User & Date: mistachkin 2015-01-12 23:44:07.346
Context
2015-01-13
02:20
Add SQLite_ForceLogPrepare environment variable to force logging of all prepared SQL regardless of the flags for the associated connection. Add more tests. check-in: 2f3a593340 user: mistachkin tags: tkt-8d928c3e88
2015-01-12
23:44
Do not wrap formatted DateTime values in single quotes when they are numeric. check-in: fc9e94c67d user: mistachkin tags: tkt-8d928c3e88
2015-01-09
04:11
Make the storage schema (SSDL) files more consistent with their provider names. check-in: b59de72204 user: mistachkin tags: tkt-8d928c3e88
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs.
883
884
885
886
887
888
889



890


891
892
893


894
895
896
897
898
899
900
            break;

          case PrimitiveTypeKind.Byte:
            result.Append(e.Value.ToString());
            break;

          case PrimitiveTypeKind.DateTime:



            result.Append(EscapeSingleQuote(SQLiteConvert.ToString(


                (System.DateTime)e.Value, _manifest._dateTimeFormat,
                _manifest._dateTimeKind, _manifest._dateTimeFormatString),
                false /* IsUnicode */));



            break;

          case PrimitiveTypeKind.Decimal:
            string strDecimal = ((Decimal)e.Value).ToString(CultureInfo.InvariantCulture);
            // if the decimal value has no decimal part, cast as decimal to preserve type
            // if the number has precision > int64 max precision, it will be handled as decimal by sql server







>
>
>
|
>
>

|
|
>
>







883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
            break;

          case PrimitiveTypeKind.Byte:
            result.Append(e.Value.ToString());
            break;

          case PrimitiveTypeKind.DateTime:
            bool needQuotes = NeedSingleQuotes(_manifest._dateTimeFormat);

            if (needQuotes)
                result.Append("\'");

            result.Append(SQLiteConvert.ToString(
                (System.DateTime)e.Value, _manifest._dateTimeFormat,
                _manifest._dateTimeKind, _manifest._dateTimeFormatString));

            if (needQuotes)
                result.Append("\'");

            break;

          case PrimitiveTypeKind.Decimal:
            string strDecimal = ((Decimal)e.Value).ToString(CultureInfo.InvariantCulture);
            // if the decimal value has no decimal part, cast as decimal to preserve type
            // if the number has precision > int64 max precision, it will be handled as decimal by sql server
3429
3430
3431
3432
3433
3434
3435




















3436
3437
3438
3439
3440
3441
3442
      selectStatement.From.Append(oldStatement);
      selectStatement.From.AppendLine();
      selectStatement.From.Append(") ");


      return selectStatement;
    }





















    /// <summary>
    /// Before we embed a string literal in a SQL string, we should
    /// convert all ' to '', and enclose the whole string in single quotes.
    /// </summary>
    /// <param name="s"></param>
    /// <param name="isUnicode"></param>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
      selectStatement.From.Append(oldStatement);
      selectStatement.From.AppendLine();
      selectStatement.From.Append(") ");


      return selectStatement;
    }

    /// <summary>
    /// Determines if values of the specified <see cref="SQLiteDateFormats" />
    /// require wrapping in single quotes.
    /// </summary>
    /// <param name="format">
    /// The <see cref="SQLiteDateFormats" /> format.
    /// </param>
    /// <returns>
    /// Non-zero if single quotes are required for a value in the specified
    /// <see cref="SQLiteDateFormats" />.
    /// </returns>
    private static bool NeedSingleQuotes(
        SQLiteDateFormats format
        )
    {
        return format != SQLiteDateFormats.Ticks &&
            format != SQLiteDateFormats.JulianDay &&
            format != SQLiteDateFormats.UnixEpoch;
    }

    /// <summary>
    /// Before we embed a string literal in a SQL string, we should
    /// convert all ' to '', and enclose the whole string in single quotes.
    /// </summary>
    /// <param name="s"></param>
    /// <param name="isUnicode"></param>