Building own Database engine

How to Build Database Engine using C#

Hello friends, this article will tell you how to write your own database engine. In fact, I do not know how true it is to call it a Database Engine, but it will work very well and we can use everywhere a DLL will be sure. A system that works independent of the Database Engine of its own so it’s not speaking we are writing this we can write the DLL, and I also use SQL commands to access this article I’m going to talk simple but very useful. Of course, you can write an even more advanced system.

In C#, you can create a DLL project. To do this, open C# and select the Class Library template from the new project option.

Then we save the database by typing the name. When the project is opened, let’s make some changes in our class structure first. I’ll tell you for access. For example, if you want to create a new table, you can create a new table by using the CREATE TABLE command in the CREATE TABLE dialog box. The use of two objects is the same. Class name Class1.not in cs Access.change it to CS. Then let’s add some references to the area where the using namespace is located.:

The first parameter that has two parameters of this command is the string variable required for the SELECT query, and the second one is the datagridview object to display the results in which this SELECT query will run. If you notice here, the DataTable object defined in the method list if the reason is that if the other would interfere with the tables in the query were defined as global so it was a nuisance. I have tried this, and some unwanted situations occurred, and I have already used this object for this method, so I decided to define it in a more accurate approach. The rest of the code you already know the code dt variable is cleaned first, although the newly defined each time re-created, but we have cleaned so that trouble does not come. Then, run the SELECT query. Then it appears in the exported DataGrid. Dtg.DataSource = dt; command. As you know, the DTG value is going to be the DataGrid we provide. In the TRY block, if the code runs correctly, the return value is true if there is no error. If the error occurs, the return value is false. This method must be a type to return a value, so it does not return a value if it is void. If the return value is true or False, The type of this method must be Boolean. Now, let’s type the command you need to run other queries, except select. In this command, CREATE, ALTER, drop, DELETE, INSERT, UPDATE, and so on. as you know, the standard SQL commands will run.

public static bool Sorgu_Çalıştır( string sql_komut)
{
try
{
c.Close();
c.Open();
com.Connection = c;
com.CommandText = sql_komut;
com.CommandType = CommandType.Text;
com.ExecuteNonQuery();
c.Close();
return true;
}
catch
{
return false;
}
}

This method returns a value of type bool back and has only one parameter. You already know the commands you use in these commands. That’s why I’m not going into much detail here. Now let’s write some more unusual commands. This command is not much different from the others, but I think it would be a bit different to use the command yazacağımız. Now that we have the command Veri_Çek command, this command will do the following example I give the Product table 3.line 5.he’il give us the information in the column. This is how it’s gonna be:

public static string Veri_Çek( string tablo, int satır, int sutun)
{
string veri = "";
int i = 0;
try
{
c.Close();
c.Open();
com.CommandType = CommandType.TableDirect;
com.CommandText = tablo;
com.Connection = c;
dr = com.ExecuteReader();
while (dr.Read() == true)
{
if (satır == i)
{
veri = dr[sutun].ToString();
break;
}
i++;
}
return veri;
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}

For example, if you want to create a new object, you must create a new object with the same name as the object you want to create. The address column and row from which the table then this information is parameterized as in this method we have to write 3 is going. It is the data variable that is defined as a string, which is the data variable that is defined as a string. A variable is a variable that is defined by the name of the variable. Then try closing it in case the connection is open. If it’s already closed, it’s okay. Then it opens. We know the part that goes through the while loop. In this fight, the DR variable is read. He reads all the records. When we want to get a value, dr[] will type the name or number of that field in square brackets, and I used the number. So dr[0].When we say toString (), that line is 0. it gives us the data in the column. The given line number is stored in the line variable. In the loop, the i variable is incremented by a constant with the I++; command. If the variable i is synchronized with the line, it says this is the given line number and goes below the if structure. Here, the information in the column specified in the data variable is discarded and sent back to where the method is called with the return command.

You can also use the ARROW KEYS to move the cursor to another command.

Returns the value of a row in a list of records. So we can learn the number of records using this command. This is a list of the records that are defined in the List<string> variable in the field we provide .Adds with Add method. We can use this command to retrieve the number of records or the information in the row we want in that field or search in that field. For example, read(“user”, 0).When we write count, 0. we can obtain the number of records in the field in the user table. 0. 0 if it doesn’t matter if the field is empty.no information in the area, but 1. if there is information in the field and there are 3 records, it returns to us as 3. We will see the use of this command in a moment.

This article has been published from the source link without modifications to the text. Only the headline has been changed.

Source link