Ejemplo n.º 1
0
 public void Run()
 {
     accessorFrom = new SqliteAccessor {
         DataSource = DataSourceFrom, Password = PasswordFrom
     };
     accessorFrom.Open();
     accessorTo = new SqliteAccessor {
         DataSource = DataSourceTo, Password = PasswordTo
     };
     accessorTo.Open();
     FetchTables();
     tables.ForEach(t => {
         CreateTable(t.Sql);
         if (t.HasBlob)
         {
             TransferBlob(t);
         }
         else
         {
             TransferNoBlob(t);
         }
     });
     accessorFrom.Close();
     accessorTo.Close();
 }
Ejemplo n.º 2
0
        public static void Register(
            bool insert,
            string key,
            string value,
            List <object> tags
            )
        {
            using var accessor = new SqliteAccessor {
                      DataSource  = AppBehind.Get.DBFilePath,
                      Password    = AppBehind.Get.Password,
                      QueryString = insert ? INSERT : UPDATE
                  };
            accessor.Open();
            var transaction = accessor.Begin();

            try {
                var command = accessor.CreateCommand();
                command.Parameters.AddWithValue(@"@key", key);
                command.Parameters.AddWithValue(@"@value", value);
                accessor.Execute(command);
                StringTags.Register(accessor, key, tags);
                transaction.Commit();
            }
            catch (Exception) {
                transaction.Rollback();
                throw;
            }
        }
Ejemplo n.º 3
0
 protected void CreateTable()
 {
     using var accessor = new SqliteAccessor {
               DataSource  = AppBehind.Get.DBFilePath,
               Password    = AppBehind.Get.Password,
               QueryString = GetQueryCreateTable()
           };
     accessor.Open();
     accessor.Execute(accessor.CreateCommand());
 }
Ejemplo n.º 4
0
 protected bool TableExists()
 {
     using var accessor = new SqliteAccessor {
               DataSource  = AppBehind.Get.DBFilePath,
               Password    = AppBehind.Get.Password,
               QueryString = GetQueryTableExists()
           };
     accessor.Open();
     return(0 < (long)accessor.ExecuteScalar(accessor.CreateCommand()));
 }
Ejemplo n.º 5
0
        public static void Retrieve(string key, FileStream outputStream)
        {
            using var accessor = new SqliteAccessor {
                      DataSource  = AppBehind.Get.DBFilePath,
                      Password    = AppBehind.Get.Password,
                      QueryString = SELECT_BLOB_WITH_KEY
                  };
            accessor.Open();
            var command = accessor.CreateCommand();

            command.Parameters.AddWithValue(@"@key", key);
            accessor.RetrieveBlob(command, outputStream, 0);
        }
Ejemplo n.º 6
0
        protected List <List <object> > Query(string query, Dictionary <string, string> parameters)
        {
            using var accessor = new SqliteAccessor {
                      DataSource  = AppBehind.Get.DBFilePath,
                      Password    = AppBehind.Get.Password,
                      QueryString = query
                  };
            accessor.Open();
            var command = accessor.CreateCommand();

            parameters.ToList().ForEach(p => { command.Parameters.AddWithValue(p.Key, p.Value); });
            accessor.Execute(command);
            return(CloneQueryResult(accessor.QueryResult));
        }
Ejemplo n.º 7
0
        public static void Register(bool insert, string newTag, string oldTag)
        {
            using var accessor = new SqliteAccessor {
                      DataSource  = AppBehind.Get.DBFilePath,
                      Password    = AppBehind.Get.Password,
                      QueryString = insert ? INSERT : UPDATE
                  };
            accessor.Open();
            var command = accessor.CreateCommand();

            command.Parameters.AddWithValue(@"@tag", newTag);
            if (!insert)
            {
                command.Parameters.AddWithValue(@"@oldTag", oldTag);
            }
            accessor.Execute(command);
        }
Ejemplo n.º 8
0
        private void PerformQueryWholeTable(string tableName)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                return;
            }
            var tableInfo = new Schema().QueryTableInfo(tableName);

            if (0 == tableInfo.Count)
            {
                return;
            }
            var query = @" SELECT " + '\n';

            query += tableInfo
                     .Select((row, index) => new { index, columnName = row[1] })
                     .Aggregate(@"",
                                (ret, item) =>
                                0 == item.index
                            ? ret + @"     " + item.columnName + @" " + '\n'
                            : ret + @"   , " + item.columnName + @" " + '\n');

            query += @" FROM " + '\n';
            query += @"     " + tableName + @" " + '\n';
            var accessor = new SqliteAccessor {
                DataSource  = AppBehind.Get.DBFilePath,
                Password    = AppBehind.Get.Password,
                QueryString = query
            };

            accessor.Open();
            accessor.Execute(accessor.CreateCommand());
            accessor.Close();
            AppBehind.Get.SetQueryString(query);
            AppBehind.Get.AddPage(accessor);
        }
Ejemplo n.º 9
0
        public static void Register(
            bool insert,
            string key,
            string filePath,
            string fileName,
            List <object> tags
            )
        {
            using var accessor = new SqliteAccessor {
                      DataSource  = AppBehind.Get.DBFilePath,
                      Password    = AppBehind.Get.Password,
                      QueryString = insert ? INSERT : UPDATE
                  };
            accessor.Open();
            var transaction = accessor.Begin();

            try {
                var command = accessor.CreateCommand();
                command.Parameters.AddWithValue(@"@key", key);
                command.Parameters.AddWithValue(@"@fileName", fileName);
                command.Parameters.AddWithValue(@"@length", new FileInfo(filePath).Length);
                using var inputStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                accessor.WriteBlob(
                    inputStream,
                    @"BINARY_STORAGE",
                    @"VALUE",
                    (long)accessor.ExecuteScalar(command)
                    );
                BinaryTags.Register(accessor, key, tags);
                transaction.Commit();
            }
            catch (Exception) {
                transaction.Rollback();
                throw;
            }
        }
Ejemplo n.º 10
0
 public void Open()
 {
     accessor.Open();
     transaction = null;
     commands    = new List <SqliteCommand>();
 }