#pragma once namespace scdriver { /// /// Embedded DB access manager class. Used to Create, Open, Close and Connect to embedded database /// engine. /// class __declspec( dllexport ) CEmbeddedDB { public: CEmbeddedDB(); /************************************** * * function: g e t _ c a l l _ s i z e * ************************************** * * Functional description * * return the size of the class **************************************/ int get_class_size(); /// /// Creates an empty embedded database. It consists of, system tables and transaction log file. /// To create a logical database you need to open embedded db, connect and execute CREATE DABATASE ... command. /// The logical databases are stored as subfolders under embedded db folder. When you need to move embedded db /// to other location, copy all files as well as subfolders. /// /// Path of the existing folder, where empty db will be created. /// Reserved. Pass NULL value /// If method fails, the node_exception, containing the error message, will be thrown void Create(const char *embPath, const char *dllPath); /// /// Open an embedded database. The database will be accessable only by /// the current application. The database engine (scimoredb.dll) will be loaded /// into the calling process's address space. /// /// Path of the existing folder, where empty db will be created. /// Reserved. Pass NULL value /// /// Set/Get the number of pre-allocated exclusive locks. The DELETE/UPDATE command will use /// a lock for each affected row, and hold it until the end of the transaction. The /// pool of locks is static and does not grow or shrink. For example, if MaxLocks = 100 /// and you are deleting or updating more than 100 rows, the database will throw an error. /// The default value is 65536, but you can easily change it million locks or higher. /// NOTE: set max locks value before calling Open() command. /// /// Set/Get the DB memory cache size. The cache is used to store the most used database /// fragments in the memory. The database are divided into pages and each page allocates 8KB. /// The default value is 3000, that allocates (3000*8KB) = 24 MB of the memory. The maximum value can be 120.000 pages. /// If database is large, the greater value will always benifit the performance, since fewer disk /// read/write operations needed. /// To investigate related database performance issues,use following SQL statememnts: /// 1. SELECT sum(cache_hit_ratio)/count() FROM system.mtables -- the query will return average cache hit ratio /// for all tables, if the value is less than 80%, setting large cache usually improve the performance. /// 2. SELECT * FROM [mpagecache] -- if column [page_faults] is increasing by 10+ pr. second, the database, /// in order to release memory for other pages, uses too many resources for writting dirty pages back to the disk. /// NOTE: set property value before calling Open() command. /// /// Set/Get the maximum number of the concurrent connections that can connect to the embedded database. /// The default value is 8. /// Connect() command will throw an exception if number of active connections reached the limit. /// In case you not sure who is using the connections, execute: SELECT * from system.msessions or, using manager, /// open [Sessions] form located in mydatabase->Monitor section. /// NOTE: set property value before calling Open() command. /// If method fails, the node_exception, containing the error message, will be thrown void OpenInProcess( const char *embPath, const char *dllPath, const int maxLocks = 1024*64, const int memPages = 3000, const int maxConn = 8); /// /// Open embedded database. When first client application opens the database, ScimoreDB engine will start /// and lock phsysical database files. Following, open commands, will connect to already started /// database. The Embedded DB cannot be shared between different computers, hence, on local machine, multiple clients /// may concurrently use database. /// NOTE: in some rare situations, the database opening may take a few minutes. This is because of the recovery process /// aborting transactions, that was active when db unexpectedly terminated. //// /// Path of the existing folder, where empty db will be created. /// Reserved. Pass NULL value /// /// Set/Get the number of pre-allocated exclusive locks. The DELETE/UPDATE command will use /// a lock for each affected row, and hold it until the end of the transaction. The /// pool of locks is static and does not grow or shrink. For example, if MaxLocks = 100 /// and you are deleting or updating more than 100 rows, the database will throw an error. /// The default value is 65536, but you can easily change it million locks or higher. /// NOTE: set max locks value before calling Open() command. /// /// Set/Get the DB memory cache size. The cache is used to store the most used database /// fragments in the memory. The database are divided into pages and each page allocates 8KB. /// The default value is 3000, that allocates (3000*8KB) = 24 MB of the memory. The maximum value can be 120.000 pages. /// If database is large, the greater value will always benifit the performance, since fewer disk /// read/write operations needed. /// To investigate related database performance issues,use following SQL statememnts: /// 1. SELECT sum(cache_hit_ratio)/count() FROM system.mtables -- the query will return average cache hit ratio /// for all tables, if the value is less than 80%, setting large cache usually improve the performance. /// 2. SELECT * FROM [mpagecache] -- if column [page_faults] is increasing by 10+ pr. second, the database, /// in order to release memory for other pages, uses too many resources for writting dirty pages back to the disk. /// NOTE: set property value before calling Open() command. /// /// Set/Get the maximum number of the concurrent connections that can connect to the embedded database. /// The default value is 8. /// Connect() command will throw an exception if number of active connections reached the limit. /// In case you not sure who is using the connections, execute: SELECT * from system.msessions or, using manager, /// open [Sessions] form located in mydatabase->Monitor section. /// NOTE: set property value before calling Open() command. /// If method fails, the node_exception, containing the error message, will be thrown void OpenShared( const char *embPath, const char *dllPath, const int maxLocks = 1024*64, const int memPages = 3000, const int maxConn = 8, const int timeout = 60); /// /// Close method will disconnect from embedded database engine. Connection will be closed as well. /// If, only one client was connected to the embedded database at the time, the db engine will be unloaded. /// /// If method fails, the node_exception class, containing the error message, will be thrown void Close(); /// /// The Shutdown internally calls Close() method and kill embedded database engine. In general, don't use the function, since, /// all concurrent clients will be disconnected from DB as well. /// /// If method fails, the node_exception class, containing the error message, will be thrown void Shutdown(); /// /// Initialize connection object. The initialized connection is already connected to embedded /// database, therefore, do not use connection's Open(connection_string) command. If you close connection object, you /// can't reconnect with Open(connection_string). Instead, call the Connect function again. /// The connection object offers the same functionality as client/server's connection, i.e. it can be used /// with CCommand, CRecordset... /// /// Valid instance of the connection object that will be initialized /// On success returns opened connetion, otherwise, the node_exception class , containing the error message, will be thrown void Connect(CConnection *conn); private: //HANDLE hengine; //HANDLE hshutdown; long engine_id; HMODULE dllHandle; char dllCache[MAX_PATH]; }; }