Generic Database Accessor Library

Source: Internet
Author: User
Project description

The Generic Database Accessor Project (GDAlib) is a layer on top of ADO. NET, which aids in the development of applications that interact with a database engine. currently, the only supported engine is Microsoft SQL Server 2005 and above, but in the future more will be supported. the main advantage of using GDAlib is that it simplifies the developer's work and speeds up writing the application's database block. this is because GDAlib hides a lot of common, repeating tasks that need to be solved for this objective. such tasks include: establishing and managing database connections, command caching, asynchronous operations, exception handling and logging. depending on the size and scope of the application, GDAlib can be used directly or inmarshated into the database block.

Documentation

The DLL ships with the afferent XML documentation file, so intelliisense will show you hints on how to use GDALib's methods. Documentation will come out soon. Until then, check out the following examples:

Connecting to a database

The DatabaseAccessor object features always connect to a database. the simplest, is to just specify the SQL server and the logging function. in this case authentication is done using the Windows user, the default database is set to Master and Console. writeline () is used for logging.

DatabaseAccessor dbAccessor = new DatabaseAccessor("foobarserver", new LogExceptionFunction(Console.WriteLine));

Executing SQL queries

//single table readerDataTable salesTable = dbAccessor.ExecuteReader("SELECT * FROM Sales;");//multi table readerDataTableCollection tables = dbAccessor.ExecuteMultiReader(@"SELECT * FROM Sales;                                                               SELECT * FROM Customers;");//non-query: INSERT, UPDATE, DELETEint affectedRows = dbAccessor.ExecuteNonQuery("INSERT INTO Sales(SaleId, Value) VALUES(415634,5000);");//asynchronous non-querydbAccessor.ExecuteNonQueryAsync("INSERT INTO Sales(SaleId, SaleValue) VALUES(415634,5000);");//read a single value from a table -> scalarint saleValue = dbAccessor.ExecuteScalar<int>("SELECT SaleValue FROM Sales WHERE SaleId = 4135634").GetValueOrDefault(-1);

Cached SQL commands

The caching mechanism in GDAlib is designed to keep in memory those commands that you use most often in order to greatly improve execution speed.

//insert a new row into the Sales table.//NB: in this case, the output parameter result will be an integer representing the number of affected rowsdbAccessor.CacheCommand("NewSale", "INSERT INTO Sales(SaleId, SaleValue) VALUES(@SaleId, @SaleValue);", SqlCommandType.NonQuery);dbAccessor.ExecuteCachedCommand("NewSale", out result, 415634,5000);//get all rows from the Sales table//NB: in this case, the output parameter result will be a DataTable representing the content of the Sales tabledbAccessor.CacheCommand("GetAllSales", "SELECT * FROM Sales;", SqlCommandType.Reader);dbAccessor.ExecuteCachedCommand("GetAllSales", out result);

Author

GDAlib is currently developed solely by Alex Gentea

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.