System.Data.SQLite
Check-in [6cb3a277db]
Not logged in

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

Overview
Comment:More cleanup related to empty strings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6cb3a277dbe3efcdb3c0ef991a7a9fdf1deb2081
User & Date: mistachkin 2016-03-09 22:40:17
Context
2016-03-11
00:35
Update scheduled release date for 1.0.100.0. check-in: 03b5dd0462 user: mistachkin tags: trunk
2016-03-09
22:40
More cleanup related to empty strings. check-in: 6cb3a277db user: mistachkin tags: trunk
22:34
Fix the (unsupported) legacy CryptoAPI based codec so that it no longer prevents page size changes. check-in: e39ba4bf1a user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SQLite.Designer/ChangePasswordDialog.cs.

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

    private void password_TextChanged(object sender, EventArgs e)
    {
      if (String.IsNullOrEmpty(password.Text) || password.Text == GetCurrentPassword())
      {
        confirmLabel.Enabled = false;
        passwordConfirm.Enabled = false;
        passwordConfirm.Text = "";

        if (String.IsNullOrEmpty(password.Text) && String.IsNullOrEmpty(GetCurrentPassword()) == false)
          action.Text = VSPackage.Decrypt;
        else
          action.Text = "";
      }
      else
      {
        confirmLabel.Enabled = true;
        passwordConfirm.Enabled = true;

        if (String.IsNullOrEmpty(GetCurrentPassword()) == false)







|




|







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

    private void password_TextChanged(object sender, EventArgs e)
    {
      if (String.IsNullOrEmpty(password.Text) || password.Text == GetCurrentPassword())
      {
        confirmLabel.Enabled = false;
        passwordConfirm.Enabled = false;
        passwordConfirm.Text = String.Empty;

        if (String.IsNullOrEmpty(password.Text) && String.IsNullOrEmpty(GetCurrentPassword()) == false)
          action.Text = VSPackage.Decrypt;
        else
          action.Text = String.Empty;
      }
      else
      {
        confirmLabel.Enabled = true;
        passwordConfirm.Enabled = true;

        if (String.IsNullOrEmpty(GetCurrentPassword()) == false)

Changes to SQLite.Designer/ChangeScriptDialog.cs.

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
          _defaultSave = _saveOrig.Checked;

          using (System.IO.StreamWriter writer = new System.IO.StreamWriter(save.FileName, false, Encoding.UTF8))
          {
            if ((_show.Visible == true && _saveOrig.Checked == true) || (_show.Visible == false && _splitter.Panel2Collapsed == true))
            {
              if (_show.Visible == true) writer.WriteLine("/*");
              writer.WriteLine(_original.Text.Replace("\r", "").TrimEnd('\n').Replace("\n", "\r\n"));
              if (_show.Visible == true) writer.WriteLine("*/");
            }
            if (_show.Visible == true || _splitter.Panel2Collapsed == false) 
              writer.WriteLine(_script.Text.Replace("\r", "").TrimEnd('\n').Replace("\n", "\r\n"));
          }
        }
      }
      Close();
    }

    private void _show_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)







|



|







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
          _defaultSave = _saveOrig.Checked;

          using (System.IO.StreamWriter writer = new System.IO.StreamWriter(save.FileName, false, Encoding.UTF8))
          {
            if ((_show.Visible == true && _saveOrig.Checked == true) || (_show.Visible == false && _splitter.Panel2Collapsed == true))
            {
              if (_show.Visible == true) writer.WriteLine("/*");
              writer.WriteLine(_original.Text.Replace("\r", String.Empty).TrimEnd('\n').Replace("\n", "\r\n"));
              if (_show.Visible == true) writer.WriteLine("*/");
            }
            if (_show.Visible == true || _splitter.Panel2Collapsed == false) 
              writer.WriteLine(_script.Text.Replace("\r", String.Empty).TrimEnd('\n').Replace("\n", "\r\n"));
          }
        }
      }
      Close();
    }

    private void _show_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

Changes to SQLite.Designer/Design/Column.cs.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  using System.Data;
  using System.Data.Common;
  using System.Globalization;

  internal class Column : IHaveConnection
  {
    private bool _allowNulls;
    private string _dataType = "";
    private string _defaultValue = "";
    private string _columnName = "";
    private string _origName = "";
    private string _collate;
    private DataGridViewRow _parent;
    private Unique _unique;
    private Table _table;

    internal Column(Table table, DataGridViewRow row)
    {
................................................................................
      else if (edmtype == "decimal")
      {
        int size = (row.IsNull("NUMERIC_PRECISION") == false) ? Convert.ToInt32(row["NUMERIC_PRECISION"], CultureInfo.InvariantCulture) : 53;
        int scale = (row.IsNull("NUMERIC_SCALE") == false) ? Convert.ToInt32(row["NUMERIC_SCALE"], CultureInfo.InvariantCulture) : int.MaxValue;

        if (size != 53)
        {
          string scalestr = (scale == int.MaxValue) ? "" : String.Format(CultureInfo.InvariantCulture, ",{0}", scale);
          _dataType = string.Format(CultureInfo.InvariantCulture, "{0}({1}{2})", _dataType, size, scalestr);
        }
      }
    }

    #region IHaveConnection Members








|
|
|
|







 







|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  using System.Data;
  using System.Data.Common;
  using System.Globalization;

  internal class Column : IHaveConnection
  {
    private bool _allowNulls;
    private string _dataType = String.Empty;
    private string _defaultValue = String.Empty;
    private string _columnName = String.Empty;
    private string _origName = String.Empty;
    private string _collate;
    private DataGridViewRow _parent;
    private Unique _unique;
    private Table _table;

    internal Column(Table table, DataGridViewRow row)
    {
................................................................................
      else if (edmtype == "decimal")
      {
        int size = (row.IsNull("NUMERIC_PRECISION") == false) ? Convert.ToInt32(row["NUMERIC_PRECISION"], CultureInfo.InvariantCulture) : 53;
        int scale = (row.IsNull("NUMERIC_SCALE") == false) ? Convert.ToInt32(row["NUMERIC_SCALE"], CultureInfo.InvariantCulture) : int.MaxValue;

        if (size != 53)
        {
          string scalestr = (scale == int.MaxValue) ? String.Empty : String.Format(CultureInfo.InvariantCulture, ",{0}", scale);
          _dataType = string.Format(CultureInfo.InvariantCulture, "{0}({1}{2})", _dataType, size, scalestr);
        }
      }
    }

    #region IHaveConnection Members

Changes to SQLite.Designer/Design/ForeignKey.cs.

1
2
3
4
5
6
7
8
9
10
11
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace SQLite.Designer.Design
{
  using System;
  using System.Collections.Generic;
................................................................................
          {
            if (fkey.IsDirty) dirty = true;

            list.Add(value[i]);
          }
        }
        if ((dirty == true || list.Count != _count) && _form.DialogResult == DialogResult.OK)
        _table.MakeDirty();      
      }
      return editValue;
    }
  }

  internal class ForeignKeyItem : IHaveConnectionScope
  {
................................................................................
        _onDelete = row["FKEY_ON_DELETE"].ToString();
        _match = row["FKEY_MATCH"].ToString();
      }
      else
      {
        _id = -1;
        _ordinal = -1;
        _from = new ForeignKeyFromItem(this, "");
        _to = new ForeignKeyToItem(this, _table.Catalog, "", "");
      }
    }

    //internal void WriteSql(StringBuilder builder)
    //{
    //  if (String.IsNullOrEmpty(_from.Column) == false && String.IsNullOrEmpty(_to.Catalog) == false &&
    //    String.IsNullOrEmpty(_to.Table) == false && String.IsNullOrEmpty(_to.Column) == false)



|







 







|







 







|
|







1
2
3
4
5
6
7
8
9
10
11
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace SQLite.Designer.Design
{
  using System;
  using System.Collections.Generic;
................................................................................
          {
            if (fkey.IsDirty) dirty = true;

            list.Add(value[i]);
          }
        }
        if ((dirty == true || list.Count != _count) && _form.DialogResult == DialogResult.OK)
        _table.MakeDirty();
      }
      return editValue;
    }
  }

  internal class ForeignKeyItem : IHaveConnectionScope
  {
................................................................................
        _onDelete = row["FKEY_ON_DELETE"].ToString();
        _match = row["FKEY_MATCH"].ToString();
      }
      else
      {
        _id = -1;
        _ordinal = -1;
        _from = new ForeignKeyFromItem(this, String.Empty);
        _to = new ForeignKeyToItem(this, _table.Catalog, String.Empty, String.Empty);
      }
    }

    //internal void WriteSql(StringBuilder builder)
    //{
    //  if (String.IsNullOrEmpty(_from.Column) == false && String.IsNullOrEmpty(_to.Catalog) == false &&
    //    String.IsNullOrEmpty(_to.Table) == false && String.IsNullOrEmpty(_to.Column) == false)

Changes to SQLite.Designer/Design/Index.cs.

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
...
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
    }

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if (destinationType == typeof(string))
      {
        StringBuilder builder = new StringBuilder();
        string separator = "";
        foreach (IndexColumn c in (List<IndexColumn>)value)
        {
          builder.AppendFormat("{0}[{1}]", separator, c.Column);
          if (c.SortMode != ColumnSortMode.Ascending)
            builder.Append(" DESC");
          if (c.Collate != "BINARY")
            builder.AppendFormat(" COLLATE {0}", c.Collate.ToUpperInvariant());
................................................................................
      return ((IHaveConnection)_table).GetConnection();
    }

    #endregion

    internal virtual void WriteSql(StringBuilder builder)
    {
      string separator = "";
      builder.AppendFormat(CultureInfo.InvariantCulture, "CREATE {0}INDEX [{1}].[{2}] ON [{3}] (", (_unique == true) ? "UNIQUE " : "", _table.Catalog, Name, _table.Name);
      foreach (IndexColumn c in Columns)
      {
        builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", separator, c.Column);
        
        if (c.SortMode != ColumnSortMode.Ascending)
          builder.Append(" DESC");

................................................................................
          int count = 0;
          string proposed = name;

          _calcname = true;
          for (int n = 0; n < _table.Indexes.Count; n++)
          {
            Index idx = _table.Indexes[n];
            proposed = String.Format(CultureInfo.InvariantCulture, "{0}{1}", name, (count > 0) ? count.ToString() : "");
            if (idx.Name == proposed)
            {
              count++;
              n = -1;
            }
          }
          _calcname = false;







|







 







|
|







 







|







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
...
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
...
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
    }

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
      if (destinationType == typeof(string))
      {
        StringBuilder builder = new StringBuilder();
        string separator = String.Empty;
        foreach (IndexColumn c in (List<IndexColumn>)value)
        {
          builder.AppendFormat("{0}[{1}]", separator, c.Column);
          if (c.SortMode != ColumnSortMode.Ascending)
            builder.Append(" DESC");
          if (c.Collate != "BINARY")
            builder.AppendFormat(" COLLATE {0}", c.Collate.ToUpperInvariant());
................................................................................
      return ((IHaveConnection)_table).GetConnection();
    }

    #endregion

    internal virtual void WriteSql(StringBuilder builder)
    {
      string separator = String.Empty;
      builder.AppendFormat(CultureInfo.InvariantCulture, "CREATE {0}INDEX [{1}].[{2}] ON [{3}] (", (_unique == true) ? "UNIQUE " : String.Empty, _table.Catalog, Name, _table.Name);
      foreach (IndexColumn c in Columns)
      {
        builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", separator, c.Column);
        
        if (c.SortMode != ColumnSortMode.Ascending)
          builder.Append(" DESC");

................................................................................
          int count = 0;
          string proposed = name;

          _calcname = true;
          for (int n = 0; n < _table.Indexes.Count; n++)
          {
            Index idx = _table.Indexes[n];
            proposed = String.Format(CultureInfo.InvariantCulture, "{0}{1}", name, (count > 0) ? count.ToString() : String.Empty);
            if (idx.Name == proposed)
            {
              count++;
              n = -1;
            }
          }
          _calcname = false;

Changes to SQLite.Designer/Design/SimpleTokenizer.cs.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
      internal bool sep;
      internal int depth;
      internal string keyword;
      internal char sepchar;

      public override string ToString()
      {
        return String.Format(CultureInfo.InvariantCulture, "{0} {1} at {2} {3} depth {4}", value, quote, position, sep == true ? "(sep)" : "", depth);
      }
    }

    public static StringParts[] BreakString(string source)
    {
      char[] opens = new char[] { '\"', '[', '\'', '(', ')', ',', ' ', ';', '\r', '\n', '\t' };
      char[] opens2 = new char[] { '\"', '[', '\'', '(', ')', ',', ' ', ';', '\r', '\n', '\t', '.' };







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
      internal bool sep;
      internal int depth;
      internal string keyword;
      internal char sepchar;

      public override string ToString()
      {
        return String.Format(CultureInfo.InvariantCulture, "{0} {1} at {2} {3} depth {4}", value, quote, position, sep == true ? "(sep)" : String.Empty, depth);
      }
    }

    public static StringParts[] BreakString(string source)
    {
      char[] opens = new char[] { '\"', '[', '\'', '(', ')', ',', ' ', ';', '\r', '\n', '\t' };
      char[] opens2 = new char[] { '\"', '[', '\'', '(', ')', ',', ' ', ';', '\r', '\n', '\t', '.' };

Changes to SQLite.Designer/Design/Table.cs.

1
2
3
4
5
6
7
8
9
10
11
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace SQLite.Designer.Design
{
  using System;
  using System.Data.Common;
................................................................................
        }
        else
        {
          _exists = false;
          return;
        }
      }
      
      _indexes.Clear();
      _oldindexes.Clear();

      using (DataTable tbl = _connection.GetSchema("Indexes", new string[] { Catalog, null, Name }))
      {
        foreach (DataRow row in tbl.Rows)
        {
................................................................................
          c.WriteSql(builder);
          separator = ",\r\n    ";
        }
      }

      if (_key.Columns.Count > 1)
      {
        string innersep = "";
        builder.AppendFormat(CultureInfo.InvariantCulture, "{0}CONSTRAINT [PK_{1}] PRIMARY KEY (", separator, Name);
        foreach (IndexColumn c in _key.Columns)
        {
          builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", innersep, c.Column);
          if (String.IsNullOrEmpty(c.Collate) == false && String.Compare(c.Collate, "BINARY", StringComparison.OrdinalIgnoreCase) != 0)
            builder.AppendFormat(CultureInfo.InvariantCulture, " COLLATE {0}", c.Collate.ToUpperInvariant());

................................................................................
      }

      builder.Append("\r\n);\r\n");

      // Rebuilding an existing table
      if (altName != null)
      {
        separator = "";
        builder.Append("\r\n-- Copy the contents of the old table into the new table\r\n");
        builder.AppendFormat("INSERT INTO [{0}].[{1}] (", _catalog, Name);
        foreach (Column c in Columns)
        {
          if (String.IsNullOrEmpty(c.OriginalName) == false)
          {
            builder.AppendFormat("{1}[{0}]", c.ColumnName, separator);
            separator = ", ";
          }
        }
        builder.Append(")\r\n  SELECT ");
        separator = "";
        foreach (Column c in Columns)
        {
          if (String.IsNullOrEmpty(c.OriginalName) == false)
          {
            builder.AppendFormat("{1}[{0}]", c.OriginalName, separator);
            separator = ", ";
          }



|







 







|







 







|







 







|











|







1
2
3
4
5
6
7
8
9
10
11
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

namespace SQLite.Designer.Design
{
  using System;
  using System.Data.Common;
................................................................................
        }
        else
        {
          _exists = false;
          return;
        }
      }

      _indexes.Clear();
      _oldindexes.Clear();

      using (DataTable tbl = _connection.GetSchema("Indexes", new string[] { Catalog, null, Name }))
      {
        foreach (DataRow row in tbl.Rows)
        {
................................................................................
          c.WriteSql(builder);
          separator = ",\r\n    ";
        }
      }

      if (_key.Columns.Count > 1)
      {
        string innersep = String.Empty;
        builder.AppendFormat(CultureInfo.InvariantCulture, "{0}CONSTRAINT [PK_{1}] PRIMARY KEY (", separator, Name);
        foreach (IndexColumn c in _key.Columns)
        {
          builder.AppendFormat(CultureInfo.InvariantCulture, "{0}[{1}]", innersep, c.Column);
          if (String.IsNullOrEmpty(c.Collate) == false && String.Compare(c.Collate, "BINARY", StringComparison.OrdinalIgnoreCase) != 0)
            builder.AppendFormat(CultureInfo.InvariantCulture, " COLLATE {0}", c.Collate.ToUpperInvariant());

................................................................................
      }

      builder.Append("\r\n);\r\n");

      // Rebuilding an existing table
      if (altName != null)
      {
        separator = String.Empty;
        builder.Append("\r\n-- Copy the contents of the old table into the new table\r\n");
        builder.AppendFormat("INSERT INTO [{0}].[{1}] (", _catalog, Name);
        foreach (Column c in Columns)
        {
          if (String.IsNullOrEmpty(c.OriginalName) == false)
          {
            builder.AppendFormat("{1}[{0}]", c.ColumnName, separator);
            separator = ", ";
          }
        }
        builder.Append(")\r\n  SELECT ");
        separator = String.Empty;
        foreach (Column c in Columns)
        {
          if (String.IsNullOrEmpty(c.OriginalName) == false)
          {
            builder.AppendFormat("{1}[{0}]", c.OriginalName, separator);
            separator = ", ";
          }

Changes to SQLite.Designer/Design/Trigger.cs.

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
          int count = 0;
          string proposed = name;

          _calcname = true;
          for (int n = 0; n < ((IList)_table.Triggers).Count; n++)
          {
            Trigger idx = ((IList)_table.Triggers)[n] as Trigger;
            proposed = string.Format(CultureInfo.InvariantCulture, "{0}{1}", name, (count > 0) ? count.ToString() : "");
            if (idx.Name == proposed)
            {
              count++;
              n = -1;
            }
          }
          _calcname = false;
................................................................................
        {
          case "UPDATE":
            _type = TriggerType.Update;
            if (arr[x + 1].keyword == "OF")
            {
              x++;
              StringBuilder builder = new StringBuilder();
              string separator = "";
              while (arr[x + 1].keyword != "ON")
              {
                builder.AppendFormat("{0}[{1}]", separator, arr[x + 1].value);
                separator = ", ";
                x++;
              }
              _columns = builder.ToString();







|







 







|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
          int count = 0;
          string proposed = name;

          _calcname = true;
          for (int n = 0; n < ((IList)_table.Triggers).Count; n++)
          {
            Trigger idx = ((IList)_table.Triggers)[n] as Trigger;
            proposed = string.Format(CultureInfo.InvariantCulture, "{0}{1}", name, (count > 0) ? count.ToString() : String.Empty);
            if (idx.Name == proposed)
            {
              count++;
              n = -1;
            }
          }
          _calcname = false;
................................................................................
        {
          case "UPDATE":
            _type = TriggerType.Update;
            if (arr[x + 1].keyword == "OF")
            {
              x++;
              StringBuilder builder = new StringBuilder();
              string separator = String.Empty;
              while (arr[x + 1].keyword != "ON")
              {
                builder.AppendFormat("{0}[{1}]", separator, arr[x + 1].value);
                separator = ", ";
                x++;
              }
              _columns = builder.ToString();

Changes to SQLite.Designer/Design/View.cs.

175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
          builder.AppendFormat("DROP TRIGGER [{0}].[{1}];\r\n", Catalog, trig.Name);
        }
        builder.AppendFormat("DROP VIEW [{0}].[{1}];\r\n", Catalog, _oldname);
      }

      builder.AppendFormat("CREATE VIEW [{0}].[{1}] AS {2};\r\n", Catalog, Name, SqlText);

      string sep = "";
      foreach (ViewTrigger trig in _triggers)
      {
        builder.Append(sep);
        trig.WriteSql(builder);
        sep = "\r\n";
      }








|







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
          builder.AppendFormat("DROP TRIGGER [{0}].[{1}];\r\n", Catalog, trig.Name);
        }
        builder.AppendFormat("DROP VIEW [{0}].[{1}];\r\n", Catalog, _oldname);
      }

      builder.AppendFormat("CREATE VIEW [{0}].[{1}] AS {2};\r\n", Catalog, Name, SqlText);

      string sep = String.Empty;
      foreach (ViewTrigger trig in _triggers)
      {
        builder.Append(sep);
        trig.WriteSql(builder);
        sep = "\r\n";
      }

Changes to SQLite.Designer/SQLiteCommandHandler.cs.

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
        TableDesignerDoc form = new TableDesignerDoc(itemId, DataViewHierarchyAccessor, tableName);
        IntPtr formptr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(form);
        Guid empty = Guid.Empty;
        FakeHierarchy fake = new FakeHierarchy(form, hier);

        int code = shell.CreateDocumentWindow(
          0, // (uint)(__VSCREATEDOCWIN.CDW_fCreateNewWindow | __VSCREATEDOCWIN.CDW_RDTFLAGS_MASK) | (uint)(_VSRDTFLAGS.RDT_CanBuildFromMemory | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_DontAddToMRU),
          form.Name, fake, (uint)itemId, formptr, formptr, ref empty, null, ref guidTableDesignContext, provider, "", form.Caption, null, out frame);

        if (frame != null)
        {
          object ret;
          int prop = (int)__VSFPROPID.VSFPROPID_Caption;
          
          code = frame.GetProperty(prop, out ret);
................................................................................
        ViewDesignerDoc form = new ViewDesignerDoc(itemId, DataViewHierarchyAccessor, viewName);
        IntPtr formptr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(form);
        Guid empty = Guid.Empty;
        FakeHierarchy fake = new FakeHierarchy(form, hier);

        int code = shell.CreateDocumentWindow(
          0, // (uint)(__VSCREATEDOCWIN.CDW_fCreateNewWindow | __VSCREATEDOCWIN.CDW_RDTFLAGS_MASK) | (uint)(_VSRDTFLAGS.RDT_CanBuildFromMemory | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_DontAddToMRU),
          form.Name, fake, (uint)itemId, formptr, formptr, ref empty, null, ref guidViewDesignContext, provider, "", form.Caption, null, out frame);

        if (frame != null)
        {
          object ret;
          int prop = (int)__VSFPROPID.VSFPROPID_Caption;

          code = frame.GetProperty(prop, out ret);







|







 







|







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
        TableDesignerDoc form = new TableDesignerDoc(itemId, DataViewHierarchyAccessor, tableName);
        IntPtr formptr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(form);
        Guid empty = Guid.Empty;
        FakeHierarchy fake = new FakeHierarchy(form, hier);

        int code = shell.CreateDocumentWindow(
          0, // (uint)(__VSCREATEDOCWIN.CDW_fCreateNewWindow | __VSCREATEDOCWIN.CDW_RDTFLAGS_MASK) | (uint)(_VSRDTFLAGS.RDT_CanBuildFromMemory | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_DontAddToMRU),
          form.Name, fake, (uint)itemId, formptr, formptr, ref empty, null, ref guidTableDesignContext, provider, String.Empty, form.Caption, null, out frame);

        if (frame != null)
        {
          object ret;
          int prop = (int)__VSFPROPID.VSFPROPID_Caption;
          
          code = frame.GetProperty(prop, out ret);
................................................................................
        ViewDesignerDoc form = new ViewDesignerDoc(itemId, DataViewHierarchyAccessor, viewName);
        IntPtr formptr = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(form);
        Guid empty = Guid.Empty;
        FakeHierarchy fake = new FakeHierarchy(form, hier);

        int code = shell.CreateDocumentWindow(
          0, // (uint)(__VSCREATEDOCWIN.CDW_fCreateNewWindow | __VSCREATEDOCWIN.CDW_RDTFLAGS_MASK) | (uint)(_VSRDTFLAGS.RDT_CanBuildFromMemory | _VSRDTFLAGS.RDT_NonCreatable | _VSRDTFLAGS.RDT_VirtualDocument | _VSRDTFLAGS.RDT_DontAddToMRU),
          form.Name, fake, (uint)itemId, formptr, formptr, ref empty, null, ref guidViewDesignContext, provider, String.Empty, form.Caption, null, out frame);

        if (frame != null)
        {
          object ret;
          int prop = (int)__VSFPROPID.VSFPROPID_Caption;

          code = frame.GetProperty(prop, out ret);

Changes to SQLite.Designer/SQLiteDataSourceInformation.cs.

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      AddProperty(IdentifierOpenQuote, "[");
      AddProperty(IdentifierCloseQuote, "]");
      AddProperty(CatalogSeparator, ".");
      AddProperty(CatalogSupported, true);
      AddProperty(CatalogSupportedInDml, true);
      AddProperty(SchemaSupported, false);
      AddProperty(SchemaSupportedInDml, false);
      AddProperty(SchemaSeparator, "");
      AddProperty(ParameterPrefix, "@");
      AddProperty(ParameterPrefixInName, true);
      AddProperty("DeskTopDataSource", true);
      AddProperty("LocalDatabase", true);
    }
  }
}







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      AddProperty(IdentifierOpenQuote, "[");
      AddProperty(IdentifierCloseQuote, "]");
      AddProperty(CatalogSeparator, ".");
      AddProperty(CatalogSupported, true);
      AddProperty(CatalogSupportedInDml, true);
      AddProperty(SchemaSupported, false);
      AddProperty(SchemaSupportedInDml, false);
      AddProperty(SchemaSeparator, String.Empty);
      AddProperty(ParameterPrefix, "@");
      AddProperty(ParameterPrefixInName, true);
      AddProperty("DeskTopDataSource", true);
      AddProperty("LocalDatabase", true);
    }
  }
}

Changes to System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs.

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
....
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
....
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
....
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
....
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
....
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
      }

      using (IEnumerator<EdmProperty> members = groupByType.Properties.GetEnumerator())
      {
        members.MoveNext();
        Debug.Assert(result.Select.IsEmpty);

        string separator = "";

        foreach (DbExpression key in e.Keys)
        {
          EdmProperty member = members.Current;
          string alias = QuoteIdentifier(member.Name);

          result.GroupBy.Append(separator);
................................................................................

      // Otherwise simply build this out as a union-all ladder
      CollectionType collectionType = MetadataHelpers.GetEdmType<CollectionType>(e.ResultType);
      Debug.Assert(collectionType != null);
      bool isScalarElement = MetadataHelpers.IsPrimitiveType(collectionType.TypeUsage);

      SqlBuilder resultSql = new SqlBuilder();
      string separator = "";

      // handle empty table
      if (e.Arguments.Count == 0)
      {
        Debug.Assert(isScalarElement);
        resultSql.Append(" SELECT NULL");
        resultSql.Append(" AS X FROM (SELECT 1) AS Y WHERE 1=0");
................................................................................

      // Process each of the inputs, and then the joinCondition if it exists.
      // It would be nice if we could call VisitInputExpression - that would
      // avoid some code duplication
      // but the Join postprocessing is messy and prevents this reuse.
      symbolTable.EnterScope();

      string separator = "";
      bool isLeftMostInput = true;
      int inputCount = inputs.Count;
      for (int idx = 0; idx < inputCount; idx++)
      {
        DbExpressionBinding input = inputs[idx];

        if (separator != "")
        {
          result.From.AppendLine();
        }
        result.From.Append(separator + " ");
        // Change this if other conditions are required
        // to force the child to produce a nested SqlStatement.
        bool needsJoinContext = (input.Expression.ExpressionKind == DbExpressionKind.Scan)
................................................................................
      SqlBuilder result = new SqlBuilder();
      RowType rowType = e.ResultType.EdmType as RowType;

      if (null != rowType)
      {
        //_typeDefs.Length = 0;
        ReadOnlyMetadataCollection<EdmProperty> members = rowType.Properties;
        string separator = "";
        for (int i = 0; i < e.Arguments.Count; ++i)
        {
          DbExpression argument = e.Arguments[i];
          if (MetadataHelpers.IsRowType(argument.ResultType))
          {
            // We do not support nested records or other complex objects.
            throw new NotSupportedException();
................................................................................
      {
        throw new InvalidOperationException("Niladic functions cannot have parameters");
      }

      if (!isNiladicFunction)
      {
        result.Append("(");
        string separator = "";
        foreach (DbExpression arg in e.Arguments)
        {
          result.Append(separator);
          result.Append(arg.Accept(this));
          separator = ", ";
        }
        result.Append(")");
................................................................................
      // be expanded in another SELECT *
      List<Symbol> columnList = new List<Symbol>();

      // A lookup for the previous set of columns to aid column name
      // collision detection.
      Dictionary<string, Symbol> columnDictionary = new Dictionary<string, Symbol>(StringComparer.OrdinalIgnoreCase);

      string separator = "";
      // The Select should usually be empty before we are called,
      // but we do not mind if it is not.
      if (!selectStatement.Select.IsEmpty)
      {
        separator = ", ";
      }

................................................................................
    /// Translates a list of SortClauses.
    /// Used in the translation of OrderBy
    /// </summary>
    /// <param name="orderByClause">The SqlBuilder to which the sort keys should be appended</param>
    /// <param name="sortKeys"></param>
    void AddSortKeys(SqlBuilder orderByClause, IList<DbSortClause> sortKeys)
    {
      string separator = "";
      foreach (DbSortClause sortClause in sortKeys)
      {
        orderByClause.Append(separator);
        orderByClause.Append(sortClause.Expression.Accept(this));
        Debug.Assert(sortClause.Collation != null);
        if (!String.IsNullOrEmpty(sortClause.Collation))
        {







|







 







|







 







|






|







 







|







 







|







 







|







 







|







1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
....
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
....
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
....
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
....
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
....
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
....
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
      }

      using (IEnumerator<EdmProperty> members = groupByType.Properties.GetEnumerator())
      {
        members.MoveNext();
        Debug.Assert(result.Select.IsEmpty);

        string separator = String.Empty;

        foreach (DbExpression key in e.Keys)
        {
          EdmProperty member = members.Current;
          string alias = QuoteIdentifier(member.Name);

          result.GroupBy.Append(separator);
................................................................................

      // Otherwise simply build this out as a union-all ladder
      CollectionType collectionType = MetadataHelpers.GetEdmType<CollectionType>(e.ResultType);
      Debug.Assert(collectionType != null);
      bool isScalarElement = MetadataHelpers.IsPrimitiveType(collectionType.TypeUsage);

      SqlBuilder resultSql = new SqlBuilder();
      string separator = String.Empty;

      // handle empty table
      if (e.Arguments.Count == 0)
      {
        Debug.Assert(isScalarElement);
        resultSql.Append(" SELECT NULL");
        resultSql.Append(" AS X FROM (SELECT 1) AS Y WHERE 1=0");
................................................................................

      // Process each of the inputs, and then the joinCondition if it exists.
      // It would be nice if we could call VisitInputExpression - that would
      // avoid some code duplication
      // but the Join postprocessing is messy and prevents this reuse.
      symbolTable.EnterScope();

      string separator = String.Empty;
      bool isLeftMostInput = true;
      int inputCount = inputs.Count;
      for (int idx = 0; idx < inputCount; idx++)
      {
        DbExpressionBinding input = inputs[idx];

        if (separator != String.Empty)
        {
          result.From.AppendLine();
        }
        result.From.Append(separator + " ");
        // Change this if other conditions are required
        // to force the child to produce a nested SqlStatement.
        bool needsJoinContext = (input.Expression.ExpressionKind == DbExpressionKind.Scan)
................................................................................
      SqlBuilder result = new SqlBuilder();
      RowType rowType = e.ResultType.EdmType as RowType;

      if (null != rowType)
      {
        //_typeDefs.Length = 0;
        ReadOnlyMetadataCollection<EdmProperty> members = rowType.Properties;
        string separator = String.Empty;
        for (int i = 0; i < e.Arguments.Count; ++i)
        {
          DbExpression argument = e.Arguments[i];
          if (MetadataHelpers.IsRowType(argument.ResultType))
          {
            // We do not support nested records or other complex objects.
            throw new NotSupportedException();
................................................................................
      {
        throw new InvalidOperationException("Niladic functions cannot have parameters");
      }

      if (!isNiladicFunction)
      {
        result.Append("(");
        string separator = String.Empty;
        foreach (DbExpression arg in e.Arguments)
        {
          result.Append(separator);
          result.Append(arg.Accept(this));
          separator = ", ";
        }
        result.Append(")");
................................................................................
      // be expanded in another SELECT *
      List<Symbol> columnList = new List<Symbol>();

      // A lookup for the previous set of columns to aid column name
      // collision detection.
      Dictionary<string, Symbol> columnDictionary = new Dictionary<string, Symbol>(StringComparer.OrdinalIgnoreCase);

      string separator = String.Empty;
      // The Select should usually be empty before we are called,
      // but we do not mind if it is not.
      if (!selectStatement.Select.IsEmpty)
      {
        separator = ", ";
      }

................................................................................
    /// Translates a list of SortClauses.
    /// Used in the translation of OrderBy
    /// </summary>
    /// <param name="orderByClause">The SqlBuilder to which the sort keys should be appended</param>
    /// <param name="sortKeys"></param>
    void AddSortKeys(SqlBuilder orderByClause, IList<DbSortClause> sortKeys)
    {
      string separator = String.Empty;
      foreach (DbSortClause sortClause in sortKeys)
      {
        orderByClause.Append(separator);
        orderByClause.Append(sortClause.Expression.Accept(this));
        Debug.Assert(sortClause.Collation != null);
        if (!String.IsNullOrEmpty(sortClause.Collation))
        {

Changes to test/TestCases.cs.

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
...
880
881
882
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
908
            cnn.Close();

            // Try re-opening with good password
            cnn.SetPassword("mypassword");
            cnn.Open();

            // Decrpyt database
            cnn.ChangePassword("");

            cnn.Close();

            ///////////////////////////////////////////////////////////////////

            cnn.Open();

................................................................................
            using (DbCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = "CREATE TABLE ChangePasswordTest2(ID int primary key)";
                cmd.ExecuteNonQuery();
            }

            // Decrpyt database
            cnn.ChangePassword("");
            cnn.Close();

            ///////////////////////////////////////////////////////////////////

            // Try opening now without password
            cnn.Open();
            cnn.Close();
................................................................................
                  for (int n = 0; n < 10000; n++)
                  {
                    DataRow row = tbl.NewRow();
                    row[1] = n + (50000 * ((bWithIdentity == true) ? 2 : 1));
                    tbl.Rows.Add(row);
                  }

                  //Console.WriteLine(String.Format("          Inserting using CommandBuilder and DataAdapter\r\n          ->{0} (10,000 rows) ...", (bWithIdentity == true) ? "(with identity fetch)" : ""));
                  int dtStart = Environment.TickCount;
                  adp.Update(tbl);
                  int dtEnd = Environment.TickCount;
                  dtEnd -= dtStart;
                  builder.AppendFormat("Insert Ends in {0} ms ... ", (dtEnd));

                  dtStart = Environment.TickCount;
................................................................................

      using (DbCommand cmd = _cnn.CreateCommand())
      {
        foreach(string table in droptables)
        {
          try
          {
            cmd.CommandText = String.Format("DROP TABLE{1} [{0}]", table, (throwError == false) ? " IF EXISTS" : "");
            cmd.ExecuteNonQuery();
          }
          catch (Exception e)
          {
            if (throwError == true)
              errors += String.Format("{0}\r\n", e.Message);
          }
        }

        foreach (string table in maydroptable)
        {
          try
          {
            cmd.CommandText = String.Format("DROP TABLE{1} [{0}]", table, (throwError == false) ? " IF EXISTS" : "");
            cmd.ExecuteNonQuery();
          }
          catch (Exception)
          {
          }
        }
      }







|







 







|







 







|







 







|













|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
...
880
881
882
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
908
            cnn.Close();

            // Try re-opening with good password
            cnn.SetPassword("mypassword");
            cnn.Open();

            // Decrpyt database
            cnn.ChangePassword(String.Empty);

            cnn.Close();

            ///////////////////////////////////////////////////////////////////

            cnn.Open();

................................................................................
            using (DbCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = "CREATE TABLE ChangePasswordTest2(ID int primary key)";
                cmd.ExecuteNonQuery();
            }

            // Decrpyt database
            cnn.ChangePassword(String.Empty);
            cnn.Close();

            ///////////////////////////////////////////////////////////////////

            // Try opening now without password
            cnn.Open();
            cnn.Close();
................................................................................
                  for (int n = 0; n < 10000; n++)
                  {
                    DataRow row = tbl.NewRow();
                    row[1] = n + (50000 * ((bWithIdentity == true) ? 2 : 1));
                    tbl.Rows.Add(row);
                  }

                  //Console.WriteLine(String.Format("          Inserting using CommandBuilder and DataAdapter\r\n          ->{0} (10,000 rows) ...", (bWithIdentity == true) ? "(with identity fetch)" : String.Empty));
                  int dtStart = Environment.TickCount;
                  adp.Update(tbl);
                  int dtEnd = Environment.TickCount;
                  dtEnd -= dtStart;
                  builder.AppendFormat("Insert Ends in {0} ms ... ", (dtEnd));

                  dtStart = Environment.TickCount;
................................................................................

      using (DbCommand cmd = _cnn.CreateCommand())
      {
        foreach(string table in droptables)
        {
          try
          {
            cmd.CommandText = String.Format("DROP TABLE{1} [{0}]", table, (throwError == false) ? " IF EXISTS" : String.Empty);
            cmd.ExecuteNonQuery();
          }
          catch (Exception e)
          {
            if (throwError == true)
              errors += String.Format("{0}\r\n", e.Message);
          }
        }

        foreach (string table in maydroptable)
        {
          try
          {
            cmd.CommandText = String.Format("DROP TABLE{1} [{0}]", table, (throwError == false) ? " IF EXISTS" : String.Empty);
            cmd.ExecuteNonQuery();
          }
          catch (Exception)
          {
          }
        }
      }

Changes to testlinq/Program.cs.

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

          string arg = null;

          if ((args != null) && (args.Length > 0))
              arg = args[0];

          if (arg == null)
              arg = "";

          arg = arg.Trim().TrimStart('-', '/').ToLowerInvariant();

          switch (arg)
          {
              case "": // String.Empty
              case "old":







|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

          string arg = null;

          if ((args != null) && (args.Length > 0))
              arg = args[0];

          if (arg == null)
              arg = String.Empty;

          arg = arg.Trim().TrimStart('-', '/').ToLowerInvariant();

          switch (arg)
          {
              case "": // String.Empty
              case "old":