Bernd wrote:
> 
> Could you be so kind and post a small example of how to use the Backup 
> API from CSharp? I'm very interested in using it but have no clue how to 
> convert the C-example on https://www.sqlite.org/backup.html to working 
> CSharp code.
> 

Here is a quick example that copies a small database from memory to disk:

using System.Data.SQLite;

namespace BackupAPI
{
  class Program
  {
    public static void BackupAndGetData()
    {
      using (SQLiteConnection source = new SQLiteConnection(
          "Data Source=:memory:"))
      {
        source.Open();

        using (SQLiteCommand command = new SQLiteCommand())
        {
          command.CommandText =
            "CREATE TABLE t1(x TEXT); " +
            "INSERT INTO t1 (x) VALUES('123456789');";

          command.Connection = source;
          command.ExecuteNonQuery();
        }

        using (SQLiteConnection destination = new SQLiteConnection(
            "Data Source=test.db"))
        {
          destination.Open();

          source.BackupDatabase(destination, "main", "main",
              -1, null, 0);
        }
      }
    }

    static void Main(string[] args)
    {
      BackupAndGetData();
    }
  }
} 

--
Joe Mistachkin

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to