Answer the question
In order to leave comments, you need to log in
How to process a selection from the database line by line?
There is a SQLite database. There is a class which works with base which I write on C#. It is necessary that I call the method of this class, it would make a selection from the base and perform actions in the program on each result (line from the selection).
If you count all the lines at once and return them to the program, then after all, they will load my entire RAM.
Passing it as a parameter in order to pull out not everything at once, but let's say 100 lines each, seems like some sort of fencing of the garden and complication.
Passing a method reference to a class (to read a string and call the passed method to process it) doesn't seem right. What is the best way to deal with such a situation?
Answer the question
In order to leave comments, you need to log in
Even so
using(var reader = sqliteCommand.ExecuteReader())
{
while(reader.Read())
{
// вызов вашего метода для конкретной строчки
}
}
using(var reader = sqliteCommand.ExecuteReader())
{
// вызов вашего метода для reader, где вы будете сами перебирать строчки
}
void Do()
{
DoSmthWithDB((Action<DataReader>)((reader) => {Console.WriteLine(reader[0].ToString());}));
}
void DoSmthWithDB(Action<DataReader> myAction)
{
...
// Создание команды к БД
...
using(var reader = sqliteCommand.ExecuteReader())
{
while(reader.Read())
{
myAction(reader); // Action<DataReader> переданный в виде параметра
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question