System.Data.SQLite

Check-in [0b89858658]
Login

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

Overview
Comment:Supports encrypted databases
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 0b89858658ec96ba7a411c24364ef7af6e6b6dbf
User & Date: rmsimpson 2006-01-10 18:41:40.000
Context
2006-01-10
21:03
1.0.24.3 beta check-in: 2620c61dbd user: rmsimpson tags: sourceforge
18:41
Supports encrypted databases check-in: 0b89858658 user: rmsimpson tags: sourceforge
18:38
no message check-in: 8dc721be16 user: rmsimpson tags: sourceforge
Changes
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite/SQLite3.cs.
520
521
522
523
524
525
526












527
528
      return UnsafeNativeMethods.sqlite3_aggregate_context_interop(context, 1);
    }

    internal override void SetRealColNames(bool bOn)
    {
      UnsafeNativeMethods.sqlite3_realcolnames(_sql, Convert.ToInt32(bOn));
    }












  }
}







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


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
      return UnsafeNativeMethods.sqlite3_aggregate_context_interop(context, 1);
    }

    internal override void SetRealColNames(bool bOn)
    {
      UnsafeNativeMethods.sqlite3_realcolnames(_sql, Convert.ToInt32(bOn));
    }

    internal override void SetPassword(byte[] passwordBytes)
    {
      int n = UnsafeNativeMethods.sqlite3_key_interop(_sql, passwordBytes, passwordBytes.Length);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }

    internal override void ChangePassword(byte[] newPasswordBytes)
    {
      int n = UnsafeNativeMethods.sqlite3_rekey_interop(_sql, newPasswordBytes, (newPasswordBytes == null) ? 0 : newPasswordBytes.Length);
      if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    }
  }
}
Changes to System.Data.SQLite/SQLiteBase.cs.
181
182
183
184
185
186
187



188
189
190
191
192
193
194
    internal abstract void ReturnDouble(int context, double value);
    internal abstract void ReturnError(int context, string value);
    internal abstract void ReturnInt32(int context, Int32 value);
    internal abstract void ReturnInt64(int context, Int64 value);
    internal abstract void ReturnNull(int context);
    internal abstract void ReturnText(int context, string value);




    protected virtual void Dispose(bool bDisposing)
    {
    }

    public void Dispose()
    {
      Dispose(true);







>
>
>







181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    internal abstract void ReturnDouble(int context, double value);
    internal abstract void ReturnError(int context, string value);
    internal abstract void ReturnInt32(int context, Int32 value);
    internal abstract void ReturnInt64(int context, Int64 value);
    internal abstract void ReturnNull(int context);
    internal abstract void ReturnText(int context, string value);

    internal abstract void SetPassword(byte[] passwordBytes);
    internal abstract void ChangePassword(byte[] newPasswordBytes);

    protected virtual void Dispose(bool bDisposing)
    {
    }

    public void Dispose()
    {
      Dispose(true);
Changes to System.Data.SQLite/SQLiteConnection.cs.
82
83
84
85
86
87
88






89
90
91
92
93
94
95
  /// </item>
  /// <item>
  /// <description>Page Size</description>
  /// <description>{size in bytes}</description>
  /// <description>N</description>
  /// <description>1024</description>
  /// </item>






  /// </list>
  /// </remarks>
  public sealed class SQLiteConnection : DbConnection, ICloneable
  {
    /// <summary>
    /// State of the current connection
    /// </summary>







>
>
>
>
>
>







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  /// </item>
  /// <item>
  /// <description>Page Size</description>
  /// <description>{size in bytes}</description>
  /// <description>N</description>
  /// <description>1024</description>
  /// </item>
  /// <item>
  /// <description>Password</description>
  /// <description>{password}</description>
  /// <description>N</description>
  /// <description></description>
  /// </item>
  /// </list>
  /// </remarks>
  public sealed class SQLiteConnection : DbConnection, ICloneable
  {
    /// <summary>
    /// State of the current connection
    /// </summary>
255
256
257
258
259
260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
    /// For a full description of EFS, see the MSDN documentation.
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to encrypt</param>

    static public void EncryptFile(string databaseFileName)
    {
      int n = UnsafeNativeMethods.sqlite3_encryptfile(databaseFileName);
      if (n == 0) throw new System.ComponentModel.Win32Exception();
    }

    /// <summary>
    /// On NTFS volumes, this function removes the encryption attribute from the file,
    /// causing the file to be decrypted.  See the MSDN documentation for full details on
    /// EFS (Encrypted File System).
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to decrypt</param>

    static public void DecryptFile(string databaseFileName)
    {
      int n = UnsafeNativeMethods.sqlite3_decryptfile(databaseFileName);
      if (n == 0) throw new System.ComponentModel.Win32Exception();
    }

    /// <summary>
    /// Returns true if the file is encrypted, or false otherwise.
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to check</param>
    /// <returns>true if the file is encrypted</returns>

    static public bool IsEncrypted(string databaseFileName)
    {
      int status;
      int n = UnsafeNativeMethods.sqlite3_encryptedstatus(databaseFileName, out status);
      if (n == 0) throw new System.ComponentModel.Win32Exception();

      return (status == 1);







>
















>















>







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
    /// For a full description of EFS, see the MSDN documentation.
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to encrypt</param>
    [Obsolete("Define a password in the ConnectionString, call SetPassword() on a new open database, or call ChangePassword({password}) on an existing open database to encrypt the database file.")]
    static public void EncryptFile(string databaseFileName)
    {
      int n = UnsafeNativeMethods.sqlite3_encryptfile(databaseFileName);
      if (n == 0) throw new System.ComponentModel.Win32Exception();
    }

    /// <summary>
    /// On NTFS volumes, this function removes the encryption attribute from the file,
    /// causing the file to be decrypted.  See the MSDN documentation for full details on
    /// EFS (Encrypted File System).
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to decrypt</param>
    [Obsolete("Call ChangePassword(null) on an open connection to decrypt an encrypted database file.")]
    static public void DecryptFile(string databaseFileName)
    {
      int n = UnsafeNativeMethods.sqlite3_decryptfile(databaseFileName);
      if (n == 0) throw new System.ComponentModel.Win32Exception();
    }

    /// <summary>
    /// Returns true if the file is encrypted, or false otherwise.
    /// </summary>
    /// <remarks>
    /// Requires Win2K and above, plus a valid EFS certificate (which is beyond the scope
    /// of this function description).
    /// </remarks>
    /// <param name="databaseFileName">The file to check</param>
    /// <returns>true if the file is encrypted</returns>
    [Obsolete("EFS file encryption will be removed from future versions of this library")]
    static public bool IsEncrypted(string databaseFileName)
    {
      int status;
      int n = UnsafeNativeMethods.sqlite3_encryptedstatus(databaseFileName, out status);
      if (n == 0) throw new System.ComponentModel.Win32Exception();

      return (status == 1);
452
453
454
455
456
457
458





459

460
461
462
463
464
465
466
    /// <description>N</description>
    /// <description>Normal</description>
    /// </item>
    /// <item>
    /// <description>Page Size</description>
    /// <description>{size in bytes}</description>
    /// <description>N</description>





    /// <description>4096</description>

    /// </item>
    /// </list>
    /// </remarks>
    public override string ConnectionString
    {
      get
      {







>
>
>
>
>
|
>







461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
    /// <description>N</description>
    /// <description>Normal</description>
    /// </item>
    /// <item>
    /// <description>Page Size</description>
    /// <description>{size in bytes}</description>
    /// <description>N</description>
    /// <description>1024</description>
    /// </item>
    /// <item>
    /// <description>Password</description>
    /// <description>{password}</description>
    /// <description>N</description>
    /// <description></description>
    /// </item>
    /// </list>
    /// </remarks>
    public override string ConnectionString
    {
      get
      {
538
539
540
541
542
543
544

545
546
547
548
549
550
551
      for (n = 0; n < x; n++)
      {
        arPiece = SQLiteConvert.Split(arParts[n], '=');
        if (arPiece.Length == 2)
        {
          ls.Add(new KeyValuePair<string, string>(arPiece[0], arPiece[1]));
        }

      }
      KeyValuePair<string, string>[] ar = new KeyValuePair<string, string>[ls.Count];
      ls.CopyTo(ar, 0);

      // Return the array of key-value pairs
      return ar;
    }







>







553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
      for (n = 0; n < x; n++)
      {
        arPiece = SQLiteConvert.Split(arParts[n], '=');
        if (arPiece.Length == 2)
        {
          ls.Add(new KeyValuePair<string, string>(arPiece[0], arPiece[1]));
        }
        else throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Invalid ConnectionString format for parameter \"{0}\"", (arPiece.Length > 0) ? arPiece[0] : "null"));
      }
      KeyValuePair<string, string>[] ar = new KeyValuePair<string, string>[ls.Count];
      ls.CopyTo(ar, 0);

      // Return the array of key-value pairs
      return ar;
    }
595
596
597
598
599
600
601
602
603





604
605
606
607
608
609
610
        bool bUTF16 = (Convert.ToBoolean(FindKey(opts, "UseUTF16Encoding", "False"), CultureInfo.InvariantCulture) == true);
        SQLiteDateFormats dateFormat = String.Compare(FindKey(opts, "DateTimeFormat", "ISO8601"), "ticks", true, CultureInfo.InvariantCulture) == 0 ? SQLiteDateFormats.Ticks : SQLiteDateFormats.ISO8601;

        if (bUTF16) // SQLite automatically sets the encoding of the database to UTF16 if called from sqlite3_open16()
          _sql = new SQLite3_UTF16(dateFormat);
        else
          _sql = new SQLite3(dateFormat);

          _sql.Open(strFile);






        _dataSource = System.IO.Path.GetFileNameWithoutExtension(strFile);

        _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Synchronous={0}", FindKey(opts, "Synchronous", "Normal")));
        _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Cache_Size={0}", FindKey(opts, "Cache Size", "2000")));
        if (String.Compare(":MEMORY:", strFile, true, CultureInfo.InvariantCulture) == 0)
          _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Page_Size={0}", FindKey(opts, "Page Size", "1024")));







|
|
>
>
>
>
>







611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
        bool bUTF16 = (Convert.ToBoolean(FindKey(opts, "UseUTF16Encoding", "False"), CultureInfo.InvariantCulture) == true);
        SQLiteDateFormats dateFormat = String.Compare(FindKey(opts, "DateTimeFormat", "ISO8601"), "ticks", true, CultureInfo.InvariantCulture) == 0 ? SQLiteDateFormats.Ticks : SQLiteDateFormats.ISO8601;

        if (bUTF16) // SQLite automatically sets the encoding of the database to UTF16 if called from sqlite3_open16()
          _sql = new SQLite3_UTF16(dateFormat);
        else
          _sql = new SQLite3(dateFormat);
        
        _sql.Open(strFile);

        string password = FindKey(opts, "Password", null);

        if (String.IsNullOrEmpty(password) == false)
          _sql.SetPassword(String.IsNullOrEmpty(password) ? null : System.Text.UTF8Encoding.UTF8.GetBytes(password));

        _dataSource = System.IO.Path.GetFileNameWithoutExtension(strFile);

        _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Synchronous={0}", FindKey(opts, "Synchronous", "Normal")));
        _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Cache_Size={0}", FindKey(opts, "Cache Size", "2000")));
        if (String.Compare(":MEMORY:", strFile, true, CultureInfo.InvariantCulture) == 0)
          _sql.Execute(String.Format(CultureInfo.InvariantCulture, "PRAGMA Page_Size={0}", FindKey(opts, "Page Size", "1024")));
637
638
639
640
641
642
643




















































644
645
646
647
648
649
650
    public override ConnectionState State
    {
      get
      {
        return _connectionState;
      }
    }





















































    ///<overloads>
    /// The following commands are used to extract schema information out of the database.  Valid schema types are:
    /// <list type="bullet">
    /// <item>
    /// <description>MetaDataCollections</description>
    /// </item>







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







658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
    public override ConnectionState State
    {
      get
      {
        return _connectionState;
      }
    }

    /// <summary>
    /// Change the password (or assign a password) to an open database.
    /// </summary>
    /// <remarks>
    /// No readers or writers may be active for this process.  The database must already be open
    /// and if it already was password protected, the existing password must already have been supplied.
    /// </remarks>
    /// <param name="newPassword">The new password to assign to the database</param>
    public void ChangePassword(string newPassword)
    {
      ChangePassword(String.IsNullOrEmpty(newPassword) ? null : System.Text.UTF8Encoding.UTF8.GetBytes(newPassword));
    }

    /// <summary>
    /// Change the password (or assign a password) to an open database.
    /// </summary>
    /// <remarks>
    /// No readers or writers may be active for this process.  The database must already be open
    /// and if it already was password protected, the existing password must already have been supplied.
    /// </remarks>
    /// <param name="newPassword">The new password to assign to the database</param>
    public void ChangePassword(byte[] newPassword)
    {
      if (_connectionState != ConnectionState.Open)
        throw new InvalidOperationException();

      _sql.ChangePassword(newPassword);
    }

    /// <summary>
    /// Sets the password for a password-protected database.  A password-protected database is
    /// unusable for any operation until the password has been set.
    /// </summary>
    /// <param name="databasePassword">The password for the database</param>
    public void SetPassword(string databasePassword)
    {
      SetPassword(String.IsNullOrEmpty(databasePassword) ? null : System.Text.UTF8Encoding.UTF8.GetBytes(databasePassword));
    }

    /// <summary>
    /// Sets the password for a password-protected database.  A password-protected database is
    /// unusable for any operation until the password has been set.
    /// </summary>
    /// <param name="databasePassword">The password for the database</param>
    public void SetPassword(byte[] databasePassword)
    {
      if (_connectionState != ConnectionState.Open)
        throw new InvalidOperationException();

      _sql.SetPassword(databasePassword);
    }

    ///<overloads>
    /// The following commands are used to extract schema information out of the database.  Valid schema types are:
    /// <list type="bullet">
    /// <item>
    /// <description>MetaDataCollections</description>
    /// </item>
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
    /// <summary>
    /// Builds a MetaDataCollections schema datatable
    /// </summary>
    /// <returns>DataTable</returns>
    private static DataTable Schema_MetaDataCollections()
    {
      DataTable tbl = new DataTable("MetaDataCollections");
      DataRow row;

      tbl.Locale = CultureInfo.InvariantCulture;
      tbl.Columns.Add("CollectionName", typeof(string));
      tbl.Columns.Add("NumberOfRestrictions", typeof(int));
      tbl.Columns.Add("NumberOfIdentifierParts", typeof(int));

      tbl.BeginLoadData();

      row = tbl.NewRow();
      row.ItemArray = new object[] { "MetaDataCollections", 0, 0 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "DataSourceInformation", 0, 0 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "DataTypes", 0, 0 };
      tbl.Rows.Add(row);

      //row = tbl.NewRow();
      //row.ItemArray = new object[] { "ReservedWords", 0, 0 };
      //tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "Catalogs", 1, 1 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "Columns", 4, 4 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "Indexes", 5, 4 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "IndexColumns", 5, 4 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "Tables", 4, 3 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "Views", 3, 3 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "ViewColumns", 4, 4 };
      tbl.Rows.Add(row);

      row = tbl.NewRow();
      row.ItemArray = new object[] { "ForeignKeys", 4, 3 };
      tbl.Rows.Add(row);

      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }








<








<
<
<
|
<
<
<
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







809
810
811
812
813
814
815

816
817
818
819
820
821
822
823



824



825



826



































827
828
829
830
831
832
833
    /// <summary>
    /// Builds a MetaDataCollections schema datatable
    /// </summary>
    /// <returns>DataTable</returns>
    private static DataTable Schema_MetaDataCollections()
    {
      DataTable tbl = new DataTable("MetaDataCollections");


      tbl.Locale = CultureInfo.InvariantCulture;
      tbl.Columns.Add("CollectionName", typeof(string));
      tbl.Columns.Add("NumberOfRestrictions", typeof(int));
      tbl.Columns.Add("NumberOfIdentifierParts", typeof(int));

      tbl.BeginLoadData();




      IO.StringReader reader = new IO.StringReader(SR.MetaDataCollections);



      tbl.ReadXml(reader);



      reader.Close();




































      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }

1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }

    //private DataTable Schema_ReservedWords()
    //{
    //  DataTable tbl = new DataTable("ReservedWords");
    //  DataRow row;
    //  const string reservedWords = "LEFT INNER OUTER JOIN SELECT INSERT UPDATE LIKE ORDER BY INTEGER PRIMARY KEY ON AS IN BETWEEN";

    //  tbl.Locale = CultureInfo.InvariantCulture;
    //  tbl.Columns.Add("ReservedWord", typeof(String));

    //  tbl.BeginLoadData();

    //  string[] ar = reservedWords.Split(' ');

    //  foreach (string s in ar)
    //  {
    //    row = tbl.NewRow();
    //    row[0] = s;
    //    tbl.Rows.Add(row);
    //  }

    //  tbl.AcceptChanges();
    //  tbl.EndLoadData();

    //  return tbl;
    //}

    private DataTable Schema_DataTypes()
    {
      DataTable tbl = new DataTable("DataTypes");

      tbl.Locale = CultureInfo.InvariantCulture;
      tbl.Columns.Add("TypeName", typeof(String));
      tbl.Columns.Add("ProviderDbType", typeof(int));







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1252
1253
1254
1255
1256
1257
1258


























1259
1260
1261
1262
1263
1264
1265

      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }



























    private DataTable Schema_DataTypes()
    {
      DataTable tbl = new DataTable("DataTypes");

      tbl.Locale = CultureInfo.InvariantCulture;
      tbl.Columns.Add("TypeName", typeof(String));
      tbl.Columns.Add("ProviderDbType", typeof(int));
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
      tbl.Columns.Add("LiteralSuffix", typeof(String));
      tbl.Columns.Add("IsUnsigned", typeof(bool));
      tbl.Columns.Add("MaximumScale", typeof(short));
      tbl.Columns.Add("MinimumScale", typeof(short));
      tbl.Columns.Add("IsConcurrencyType", typeof(bool));

      tbl.BeginLoadData();
      string dataTypesXml = @"<?xml version=""1.0"" standalone=""yes""?>
<DocumentElement>
  <DataTypes>
    <TypeName>System.Int16</TypeName>
    <ProviderDbType>10</ProviderDbType>
    <ColumnSize>5</ColumnSize>
    <DataType>System.Int16</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>true</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Int32</TypeName>
    <ProviderDbType>8</ProviderDbType>
    <ColumnSize>10</ColumnSize>
    <DataType>System.Int32</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>true</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Single</TypeName>
    <ProviderDbType>15</ProviderDbType>
    <ColumnSize>7</ColumnSize>
    <DataType>System.Single</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Double</TypeName>
    <ProviderDbType>8</ProviderDbType>
    <ColumnSize>6</ColumnSize>
    <DataType>System.Double</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Decimal</TypeName>
    <ProviderDbType>7</ProviderDbType>
    <ColumnSize>19</ColumnSize>
    <DataType>System.Decimal</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>true</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Boolean</TypeName>
    <ProviderDbType>3</ProviderDbType>
    <ColumnSize>1</ColumnSize>
    <DataType>System.Boolean</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Byte</TypeName>
    <ProviderDbType>2</ProviderDbType>
    <ColumnSize>3</ColumnSize>
    <DataType>System.Byte</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>true</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>true</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Int64</TypeName>
    <ProviderDbType>12</ProviderDbType>
    <ColumnSize>19</ColumnSize>
    <DataType>System.Int64</DataType>
    <IsAutoIncrementable>true</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>true</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <IsUnsigned>false</IsUnsigned>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Byte[]</TypeName>
    <ProviderDbType>1</ProviderDbType>
    <ColumnSize>2147483647</ColumnSize>
    <DataType>System.Byte[]</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>false</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>true</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>false</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <LiteralPrefix>X'</LiteralPrefix>
    <LiteralSuffix>'</LiteralSuffix>
  </DataTypes>
  <DataTypes>
    <TypeName>System.String</TypeName>
    <ProviderDbType>16</ProviderDbType>
    <ColumnSize>2147483647</ColumnSize>
    <CreateParameters>max length</CreateParameters>
    <DataType>System.String</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>false</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>true</IsSearchableWithLike>
    <LiteralPrefix>'</LiteralPrefix>
    <LiteralSuffix>'</LiteralSuffix>
  </DataTypes>
  <DataTypes>
    <TypeName>System.DateTime</TypeName>
    <ProviderDbType>6</ProviderDbType>
    <ColumnSize>23</ColumnSize>
    <DataType>System.DateTime</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>true</IsSearchableWithLike>
    <LiteralPrefix>'</LiteralPrefix>
    <LiteralSuffix>'</LiteralSuffix>
  </DataTypes>
  <DataTypes>
    <TypeName>System.Guid</TypeName>
    <ProviderDbType>4</ProviderDbType>
    <ColumnSize>16</ColumnSize>
    <DataType>System.Guid</DataType>
    <IsAutoIncrementable>false</IsAutoIncrementable>
    <IsCaseSensitive>false</IsCaseSensitive>
    <IsFixedLength>true</IsFixedLength>
    <IsFixedPrecisionScale>false</IsFixedPrecisionScale>
    <IsLong>false</IsLong>
    <IsNullable>true</IsNullable>
    <IsSearchable>true</IsSearchable>
    <IsSearchableWithLike>false</IsSearchableWithLike>
    <LiteralPrefix>'</LiteralPrefix>
    <LiteralSuffix>'</LiteralSuffix>
  </DataTypes>
</DocumentElement>";

      IO.StringReader stringReader = new System.IO.StringReader(dataTypesXml);
      tbl.ReadXml(stringReader);
      stringReader.Close();

      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

|
|
|







1281
1282
1283
1284
1285
1286
1287



























































































































































































1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
      tbl.Columns.Add("LiteralSuffix", typeof(String));
      tbl.Columns.Add("IsUnsigned", typeof(bool));
      tbl.Columns.Add("MaximumScale", typeof(short));
      tbl.Columns.Add("MinimumScale", typeof(short));
      tbl.Columns.Add("IsConcurrencyType", typeof(bool));

      tbl.BeginLoadData();




























































































































































































      IO.StringReader reader = new IO.StringReader(SR.DataTypes);
      tbl.ReadXml(reader);
      reader.Close();

      tbl.AcceptChanges();
      tbl.EndLoadData();

      return tbl;
    }

Changes to System.Data.SQLite/SQLiteConnectionStringBuilder.cs.
133
134
135
136
137
138
139


















140
141
142
143
144
145
146
        return this["Data Source"].ToString();
      }
      set
      {
        this["Data Source"] = value;
      }
    }



















    /// <summary>
    /// Gets/Sets the page size for the connection.
    /// </summary>
    [DisplayName("Page Size")]
    [Browsable(true)]
    [DefaultValue(1024)]







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







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
        return this["Data Source"].ToString();
      }
      set
      {
        this["Data Source"] = value;
      }
    }

    /// <summary>
    /// Gets/sets the database encryption password
    /// </summary>
    [Browsable(true)]
    public string Password
    {
      get
      {
        if (ContainsKey("Password") == false) return "";

        return this["Password"].ToString();
      }
      set
      {
        this["Password"] = value;
      }
    }

    /// <summary>
    /// Gets/Sets the page size for the connection.
    /// </summary>
    [DisplayName("Page Size")]
    [Browsable(true)]
    [DefaultValue(1024)]
Changes to System.Data.SQLite/SQLiteDataReader.cs.
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
              row[SchemaTableColumn.IsUnique] = false;
              row[SchemaTableColumn.IsKey] = false;
              row[SchemaTableOptionalColumn.IsAutoIncrement] = false;
              row[SchemaTableOptionalColumn.IsReadOnly] = false;
              row[SchemaTableColumn.BaseColumnName] = GetName(n);

              // Try and extract the database, table and column from the datareader
              arName = rd.GetName(n).Split('.');

              if (arName.Length > 1)
                strTable = arName[arName.Length - 2];

              if (arName.Length > 2)
                strCatalog = arName[arName.Length - 3];








|







504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
              row[SchemaTableColumn.IsUnique] = false;
              row[SchemaTableColumn.IsKey] = false;
              row[SchemaTableOptionalColumn.IsAutoIncrement] = false;
              row[SchemaTableOptionalColumn.IsReadOnly] = false;
              row[SchemaTableColumn.BaseColumnName] = GetName(n);

              // Try and extract the database, table and column from the datareader
              arName = rd.GetName(n).Split('\x01');

              if (arName.Length > 1)
                strTable = arName[arName.Length - 2];

              if (arName.Length > 2)
                strCatalog = arName[arName.Length - 3];

Changes to System.Data.SQLite/SQLiteFunction.cs.
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
    /// <summary>
    /// Manual method of registering a function.  The type must still have the SQLiteFunctionAttributes in order to work
    /// properly, but this is a workaround for the Compact Framework where enumerating assemblies is not currently supported.
    /// </summary>
    /// <param name="typ">The type of the function to register</param>
    public static void RegisterFunction(Type typ)
    {
      object[] arAtt = typ.GetCustomAttributes(false);
      int u = arAtt.Length;
      SQLiteFunctionAttribute at;

      for (int y = 0; y < u; y++)
      {
        at = arAtt[y] as SQLiteFunctionAttribute;
        if (at != null)







|







442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
    /// <summary>
    /// Manual method of registering a function.  The type must still have the SQLiteFunctionAttributes in order to work
    /// properly, but this is a workaround for the Compact Framework where enumerating assemblies is not currently supported.
    /// </summary>
    /// <param name="typ">The type of the function to register</param>
    public static void RegisterFunction(Type typ)
    {
      object[] arAtt = typ.GetCustomAttributes(typeof(SQLiteFunctionAttribute), false);
      int u = arAtt.Length;
      SQLiteFunctionAttribute at;

      for (int y = 0; y < u; y++)
      {
        at = arAtt[y] as SQLiteFunctionAttribute;
        if (at != null)
Changes to System.Data.SQLite/System.Data.SQLite.csproj.
10
11
12
13
14
15
16
17

18
19
20

21
22
23
24
25
26
27
    <RootNamespace>System.Data.SQLite</RootNamespace>
    <AssemblyName>System.Data.SQLite</AssemblyName>
    <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <PlatformFamilyName>PocketPC</PlatformFamilyName>
    <PlatformID>3C41C503-53EF-4c2a-8DD4-A8217CAD115E</PlatformID>
    <OSVersion>4.20</OSVersion>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <FormFactorID>POCKET_PC_2003_PORTRAIT</FormFactorID>

    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>System.Data.SQLite.CF.snk</AssemblyOriginatorKeyFile>
    <DeployDirSuffix>testce</DeployDirSuffix>

  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>TRACE;DEBUG;PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>







|
>



>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    <RootNamespace>System.Data.SQLite</RootNamespace>
    <AssemblyName>System.Data.SQLite</AssemblyName>
    <ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <PlatformFamilyName>PocketPC</PlatformFamilyName>
    <PlatformID>3C41C503-53EF-4c2a-8DD4-A8217CAD115E</PlatformID>
    <OSVersion>4.20</OSVersion>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <FormFactorID>
    </FormFactorID>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>System.Data.SQLite.CF.snk</AssemblyOriginatorKeyFile>
    <DeployDirSuffix>testce</DeployDirSuffix>
    <DeployDirPrefix>%25CSIDL_PROGRAM_FILES%25</DeployDirPrefix>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>..\bin\CompactFramework\</OutputPath>
    <DefineConstants>TRACE;DEBUG;PocketPC;PLATFORM_COMPACTFRAMEWORK</DefineConstants>
82
83
84
85
86
87
88





89
90
91







92






93
94
95
96
97
98
99
    <Compile Include="SQLiteFactory.cs" />
    <Compile Include="SQLiteFunction.cs" />
    <Compile Include="SQLiteFunctionAttribute.cs" />
    <Compile Include="SQLiteParameter.cs" />
    <Compile Include="SQLiteParameterCollection.cs" />
    <Compile Include="SQLiteStatement.cs" />
    <Compile Include="SQLiteTransaction.cs" />





    <Compile Include="UnsafeNativeMethods.cs" />
  </ItemGroup>
  <ItemGroup>







    <None Include="System.Data.SQLite.CF.snk" />






  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>
  <Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <ProjectExtensions>







>
>
>
>
>



>
>
>
>
>
>
>
|
>
>
>
>
>
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    <Compile Include="SQLiteFactory.cs" />
    <Compile Include="SQLiteFunction.cs" />
    <Compile Include="SQLiteFunctionAttribute.cs" />
    <Compile Include="SQLiteParameter.cs" />
    <Compile Include="SQLiteParameterCollection.cs" />
    <Compile Include="SQLiteStatement.cs" />
    <Compile Include="SQLiteTransaction.cs" />
    <Compile Include="SR.Designer.cs">
      <DependentUpon>SR.resx</DependentUpon>
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
    </Compile>
    <Compile Include="UnsafeNativeMethods.cs" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="SR.resx">
      <SubType>Designer</SubType>
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>SR.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <None Include="System.Data.SQLite.snk" />
  </ItemGroup>
  <ItemGroup>
    <None Include="DataTypes.xml" />
  </ItemGroup>
  <ItemGroup>
    <None Include="MetaDataCollections.xml" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>
  <Import Condition="'$(TargetFrameworkVersion)' == 'v1.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.v1.targets" />
  <Import Condition="'$(TargetFrameworkVersion)' == 'v2.0'" Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
  <ProjectExtensions>
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
231
232
233
234
235
236
237






238
239
    internal static extern int sqlite3_encryptedstatus(string fileName, out int fileStatus);

    [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int sqlite3_compressfile(string fileName);

    [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int sqlite3_decompressfile(string fileName);






  }
}







>
>
>
>
>
>


231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    internal static extern int sqlite3_encryptedstatus(string fileName, out int fileStatus);

    [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int sqlite3_compressfile(string fileName);

    [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode, SetLastError = true)]
    internal static extern int sqlite3_decompressfile(string fileName);

    [DllImport(SQLITE_DLL)]
    internal static extern int sqlite3_key_interop(int db, byte[] key, int keylen);

    [DllImport(SQLITE_DLL)]
    internal static extern int sqlite3_rekey_interop(int db, byte[] key, int keylen);
  }
}