LetoDB: answers to questions,
that appears or may appears.
(New questions can be suggested at the end of the page)
- Where to get, how to install?
- Why it is called LetoDB?
- Please help me in the server modes.
- How does caching records, how to configure it?
- What should be changed in the program, to start using LetoDB?
- Can a single program to run multiple LetoDB servers?
- How to code the transaction correctly?
- In which cases transactions are useful?
- Can I use LetoDB server from programs written in C, Delphi and other languages?
Where to get, how to install?
LetoDB project is hosted on SourceForge, there it is possible to download a last official source distribution. You may also to get most fresh sources with the help of Git:
git clone http://git.code.sf.net/p/letodb/codeor here, clicking on a button "Download snapshot".
Official source distributions and some binary, ar available on my site via LetoDb page.
If you do not fit ready binaries from my site, you will need to compile
LetoDB yourself. It is not difficult, the procedure is described in details in
You may use a Harbour's Hbmk utility, or one of bat-files,
included in distribution. In the latter case, the main thing - to tell the system where the
Harbour and maybe your C compiler is placed.
If you're building a server on Windows, you need to decide whether to compile the server LetoDB as a service (the default mode), or as a normal program (service not always run equally well) - then you will have to be amended the appropriate makefile, replacing:- in letodb.hbp: lines "-cflag=" и "-prgflag=" __WIN_SERVICE__ to __WIN_DAEMON__;
- in makefile.bc, makefile.gcc: line "SRV_MODE =" __WIN_SERVICE__ to __WIN_DAEMON__.
When the executable of LetoDB server is ready, copy it to the selected directory and put there
letodb.ini with the options you desire. Create a separate directory for the database and mention it
in letodb.ini in the line
DataPath = - otherwise the newly created tables will be placed in the directory
with LetoDB executable. Then you can consider LetoDB server installed.
Why it is called LetoDB?
Because I start to write it in a cold winter ) - "Leto" means "summer" on Russian.
Please help me in the server modes.
There are three server modes, which may be set with the hekp of a main server
- Basic Mode: Share_Tables and No_Save_WA set to 0 or not set at all.
In this mode, each file is opened by the server module in exclusive mode
and only once. When another client requests the opening of a file, which is
opened already by the server, a new workarea is not created - an existing one
is used repeatedly for each client. This reduces the total number of opened files in the system,
save memory for workareas and buffers and increase the speed of some operations,
because the data access is faster in exclusive mode: file locks aren't required,
buffers are used. The disadvantages of this mode are the following:
- The impossibility of simultaneous access to database tables by LetoDB and programs, which do not use LetoDB (although it is not always a disadvantage).
- The fact that one workarea is shared by many users, has certain disadvantages. This is a regular resetting of index buffers and tables buffers, which leads to lower productivity in some cases.
- Share_Tables = 1. The difference from a basic mode is that the tables are opened by a server module not in exclusive mode, but in that one, which the client requested. It results in some performance degradation, but allows to work with DB tables from other programs in parallel with LetoDB.
- No_Save_WA = 1. This automatically set1 to 1 the Share_Tables, too. In this mode, each request to open a file creates a new workspace. If 100 customers will open the same file, the server will open it 100 times and 100 workareas will be created. On the one hand, this leads to more memory consumption and speed reducing in a number of situations because of the need to set the locks; on the other - can lead to increasing of productivity in some cases, because it fixes the second problem of a main mode.
So after all, what mode to choose ? The Share_Tables mode makes sense to consider only when you really need to use a table from other programs in parallel with LetoDB - and do not forget that No_Save_WA mode includes this option. As for the choice between the main and No_Save_WA - it is difficult to to give a definite answer. It depends on the specifics of your entire environment - server configuration and OS, network, and, finally, from the manner in which your programs are written. It is necessary to try both options and choose optimal. I can only say that at the moment (07.10.2016) No_Save_WA mode is not yet tested extensively.
How does caching records, how to configure it?
When the server receives a request to perform SKIP operation, it sends back to client not an one record, but several - in this case the client program forms a buffer with these records. While the next SKIP a client program first checks whether the desired record is in the buffer, and only if not - it sends a new request to the server. The lifetime of such a buffer is limited by one second, which is sufficient for caching of a series of moving operations on the table and, however, it does not lead to the fact that changes in the table made by another client, would go unnoticed you.
The default size of the buffer - 10 records, it can be changed in the
setting Cache_Records. In addition, this parameter can be set individually
for each table, using a call of a
leto_SetSkipBuffer (nRecords) function - it
sets the buffer size to
nRecords for the current workarea.
The caching is especially effective when you are moving sequentially through a lot of records, but may slow down the work, if you do not do a few SKIPs in sequence because sending of multiple records requires more time than one. Therefore, to increase a productivity it has a sense to set the buffer size individually for different tables depending on how they are used.
What should be changed in the program, to start using LetoDB?
Since the client part of LetoDB is an RDD, you just need to link the rddleto library to your application and write a couple of lines:
REQUEST LETO RDDSETDEFAULT( "LETO" )
Actually, that's all. And, of course, while the creation and opening of the database tables
it is needed to specify the path to the server - ip or domain name and the port (2812,
if some other isn't specified in
letodb.ini. See the examples in the
It is useful, but not required, to establish a connection to the server before you start working with the data on it: just to make sure that the connection exists:
IF ( leto_Connect( cPath ) ) == -1 ? "Connection failed." Return Nil ELSE ? "Ok" ENDIF
Can a single program to run multiple LetoDB servers?
Yes, it can. When a full path is specified in the command to open or create a table or in the file access functions, Leto extracts the server address and port number from this path, checks whether you have connected to this server and, if not, connects to it. A number of connected servers is not limited.
In some functions, for example, those intended for recording/reading of LetoDB variables
(leto_var ... ()), the path to the server is not specified. In this case, the
current connection is used. If you have multiple
open connections, the current can be set by calling the function
leto_SetCurrentConnection(cConnString | nConnection).
The parameter may be a path to the server (this could be any file path on the server),
and a connection number. The function returns the number of connection, which was current
before a function call:
nConn := leto_SetCurrentConnection( cPath2 ) leto_VarSet( ... ) ... leto_SetCurrentConnection( nConn )
How to code the transaction correctly?
The transaction always begins with a call of
and ends with a call of
leto_CommitTransaction(). Between then - operations,
changing the database tables: APPEND, REPLACE, DELETE.
Note that these write operations are buffered on the client side and are sent for execution
to the server by calling
leto_CommitTransaction(), while the other operations - moving in the table,
reading data are executed immediately, as usual.
Before the execution of the transaction it is necessary to make all the necessary lock, otherwise it will not work.
If, after the start of the transaction (call of
something will go wrong - the record locking fails, for example,
you can use the
leto_Rollback( lUnlockAll ) to exit the transaction mode.
Below is a small sample from
Function ChangeNakl( nSummNew ) Local nDelta leto_BeginTransaction() select NAKL1 if !dbSeek( Dtos(NAKL2->DORD)+STR(NAKL2->NORD) ) .or. !Rlock() leto_Rollback(.F.) Return .F. endif select NAKL2 if Rlock() nDelta := nSummNew - SUMMA replace SUMMA with nSummNew else leto_Rollback() Return .F. endif select NAKL1 replace SUMMA with SUMMA + nDelta leto_CommitTransaction() Return .T.
In which cases transactions are useful?
Transactions in LetoDB, as well as in other client-server database management system, are designed to make several logically connected changes in the database tables in this way, to ensure the preservation of data consistency, to perform them all - or none of them.
In other words, if you need to make several related changes to data - somewhere add a record, somewhere replace = merge them into the transaction.
Other possible application - to increase the speed. If you add, for example, 10 records one after the other, this will be 10 cycles of communicating with the server. And if you join these 10 additions in one transaction, it would take only one communication session. But do not overdo the amount of of additions in a single transaction: it requires large buffers, and this is not very good.
And once again I want to emphasize that the transaction work on the writing only. If there are data read or moving operations inside a transaction, they are carried out immedeately, they are not buffered, not included in the transaction.
Can I use LetoDB server from programs written in C, Delphi and other languages?
Yes, you can. The LetoDB's client part includes a static library leto.lib (or leto.a, if you use Mingw or gcc).
Link it to your application - and use a set of functions to access the server. Simple examples
in C, which uses leto.lib, you can find in
letodb/tests/c_lang/. You can also
to build leto.dll dynamic library with a help of Hbmk and letodyn.hbp - and use it with your applications.
(not be shown publicly)