Table of Contents
Server-Side Cursor Advantage
Client-Side Cursor
Most SQL Servers gives you a client-side cursor only.
curs = db.SqlSelect( "SELECT * FROM T ..." )
Server sends found N records to a client computer as snapshoot, the records are not locked on the server side. You can only read the records of such client-side cursor.
When you want to update at least one field of this selection, you should
1) generate string of UPDATE command of kind
UPDATE TABLE T SET fld = NewValue WHERE KeyFld = current_id
To generate this string, usually few lines of programming code are required.
2) Execute this UPDATE command.
3) Get back changes, i.e.
- destroy old cursor
- build a new cursor using SELECT command with same conditions.
4) If you have some front-end to that cursor, you may need to take care to show again the current record.
Valentina DB (local and server) also have client-side cursors. But it also offers server-side cursor.
Server-Side cursor of Valentina DB
In Valentina API you can ask for server-side cursor as a result.
curs = db.SqlSelect( "SELECT * FROM T ...", kServerSideCursor, kReadWrite )
In this case Valentina DB Server does not send all found records to a client computer. It sends one or few. So the first possible case for use of this cursor is - huge selections.
Besides, Valentina Server keeps record locks on selected rows of cursor. This allows to modify records!
As a result, it can be much easier to build front-end around server-side cursor. To modify field you should just
curs.Field(Name).value = NewVaue curs.UpdateRecord()
DONE.
Please note, that in this case THERE IS NO ANY SQL strings built behind this!
VCursor.UpdateRecord() is true protocol-based client-server command of Valentina API.
Advantage
Valentina's solution removes overhead of these operations:
- client: build UPDATE string generation using concatenation
- client: sending UPDATE string by protocol
- server: parsing of that string on server side
- server: send back result of UPDATE command
- client: sending of SELECT string
- server: parsing of SELECT string
- server: Executing of SELECT
- server: sending back N records by protocol
- client: extract records from protocol and build cursor with records in RAM structures.