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;
            }
        }
Exemple #2
0
        public static void Register(SqliteAccessor accessor, string key, List <object> tags)
        {
            accessor.QueryString = DELETE;
            var command = accessor.CreateCommand();

            command.Parameters.AddWithValue(@"@key", key);
            accessor.Execute(command);
            accessor.QueryString = INSERT;
            command = accessor.CreateCommand();
            for (var i = 0; tags.Count > i; ++i)
            {
                command.Parameters.Clear();
                command.Parameters.AddWithValue(@"@key", key);
                command.Parameters.AddWithValue(@"@tag", tags[i].ToString());
                accessor.Execute(command);
            }
        }
Exemple #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());
 }
Exemple #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()));
 }
Exemple #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);
        }
Exemple #6
0
        public void AddCommand(string arg)
        {
            var qs = arg.Replace(@"\r\n", @"\n").Split(';');

            foreach (var q in qs)
            {
                if (string.IsNullOrEmpty(q.Trim()))
                {
                    continue;
                }
                accessor.QueryString = q;
                commands.Add(accessor.CreateCommand());
            }
        }
Exemple #7
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));
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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;
            }
        }