L
L
ldmitriy2020-06-29 10:05:48
C++ / C#
ldmitriy, 2020-06-29 10:05:48

Where to store query result from mysql, buffering?

1) Now I'm just outputting data, but where is it usually stored? In structure, collection?

MySqlConnection connect = new MySqlConnection("server=localhost;user=root;password=1;database=test");
connect.Open();
 string sql = "SELECT * FROM TABLE1";
MySqlCommand command = new MySqlCommand(sql, connect);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    Console.Write($"{reader[i]}\t");
                }
                Console.WriteLine();
}
reader.Close();
connect.Close();


2) is the reader buffered? As I understand it, the result is stored on the server side and then line by line we get the results from it? Is it possible to get the whole query result?
Can I create a second reader without closing it and get the result?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-06-29
@freeExec

If you received line by line from the server, then the method Readwould be asynchronous, but it is not. For storage, you describe the data model and fill it.

R
Roman, 2020-07-01
@yarosroman

Change to any ORM, for example, EF, Dapper (if lightness is needed). And work immediately with models and collections.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question